📄 bcgpminiframewnd.cpp
字号:
void CBCGPMiniFrameWnd::OnDrawCaptionButtons (CDC* pDC)
{
ASSERT_VALID (pDC);
// Paint caption buttons:
for (POSITION pos = m_lstCaptionButtons.GetHeadPosition (); pos != NULL;)
{
CBCGPCaptionButton* pBtn = (CBCGPCaptionButton*) m_lstCaptionButtons.GetNext (pos);
ASSERT_VALID (pBtn);
BOOL bMaximized = TRUE;
if (pBtn->GetHit () == HTMAXBUTTON && m_bPinned)
{
bMaximized = FALSE;
}
BOOL bEnabled = TRUE;
if(CBCGPToolBar::IsCustomizeMode())
{
if ((pBtn->GetHit () == HTCLOSE) || (pBtn->GetHit () == HTCLOSE_BCG))
{
bEnabled = TRUE;
}
pBtn->m_bEnabled = bEnabled;
}
pBtn->OnDraw (pDC, TRUE, TRUE, bMaximized, !bEnabled);
}
}
//--------------------------------------------------------------------------------------//
UINT CBCGPMiniFrameWnd::OnNcHitTest(CPoint point)
{
return HitTest (point, FALSE);
}
//--------------------------------------------------------------------------------------//
UINT CBCGPMiniFrameWnd::HitTest (CPoint point, BOOL bDetectCaption)
{
// in cust. mode allow mouse processing only for floating toolbar
if (IsCustModeAndNotFloatingToolbar ())
{
return HTNOWHERE;
}
CRect rectWnd;
GetWindowRect (&rectWnd);
if (!rectWnd.PtInRect (point))
{
return HTNOWHERE;
}
CRect rectClient;
GetClientRect (&rectClient);
ClientToScreen (&rectClient);
if (rectClient.PtInRect (point))
{
return HTCLIENT;
}
CRect rectBorderSize;
CalcBorderSize (rectBorderSize);
int nCursorWidth = GetSystemMetrics (SM_CXCURSOR) / 2;
int nCursorHeight = GetSystemMetrics (SM_CYCURSOR) / 2;
CRect rectCaption (rectWnd.left + rectBorderSize.left, rectWnd.top + rectBorderSize.top,
rectWnd.right - rectBorderSize.right,
rectWnd.top + rectBorderSize.top + m_nCaptionHeight);
if (rectCaption.PtInRect (point))
{
if (bDetectCaption)
{
return HTCAPTION;
}
for (POSITION pos = m_lstCaptionButtons.GetHeadPosition (); pos != NULL;)
{
CBCGPCaptionButton* pBtn = (CBCGPCaptionButton*) m_lstCaptionButtons.GetNext (pos);
ASSERT_VALID (pBtn);
// the button's rectangle has offset relative to caption, we need to offset it
// by caption's topleft corner to get client coordinates
CRect rectBtn = pBtn->GetRect ();
rectBtn.OffsetRect (rectCaption.TopLeft ());
if (rectBtn.PtInRect (point))
{
return pBtn->GetHit ();
}
}
return HTCLIENT;
}
BOOL bEnableCornerArrows = TRUE;
CWnd* pWndEmbedded = CWnd::FromHandlePermanent (m_hEmbeddedBar);
if (pWndEmbedded != NULL && pWndEmbedded->IsKindOf (RUNTIME_CLASS (CBCGPToolBar)))
{
bEnableCornerArrows = FALSE;
}
// no corner arrows in sliding mode
bEnableCornerArrows = bEnableCornerArrows;
CRect rectBorder;
if (bEnableCornerArrows)
{
// top left corner - border
rectBorder.SetRect (rectWnd.left, rectWnd.top, rectWnd.left + nCursorWidth, rectWnd.top + nCursorHeight);
if (rectBorder.PtInRect (point))
{
return HTTOPLEFT;
}
// top border
rectBorder.SetRect (rectWnd.left + nCursorWidth, rectWnd.top,
rectWnd.right - nCursorWidth, rectWnd.top + rectBorderSize.top);
if (rectBorder.PtInRect (point))
{
return HTTOP;
}
// top right border
rectBorder.SetRect (rectWnd.right - nCursorWidth, rectWnd.top,
rectWnd.right, rectWnd.top + nCursorHeight);
if (rectBorder.PtInRect (point))
{
return HTTOPRIGHT;
}
// right border
rectBorder.SetRect (rectWnd.right - rectBorderSize.right, rectWnd.top + nCursorHeight,
rectWnd.right, rectWnd.bottom - nCursorHeight);
if (rectBorder.PtInRect (point))
{
return HTRIGHT;
}
// bottom right
rectBorder.SetRect (rectWnd.right - nCursorWidth, rectWnd.bottom - nCursorHeight,
rectWnd.right, rectWnd.bottom);
if (rectBorder.PtInRect (point))
{
return HTBOTTOMRIGHT;
}
// bottom
rectBorder.SetRect (rectWnd.left + nCursorWidth, rectWnd.bottom - rectBorderSize.bottom,
rectWnd.right - nCursorWidth, rectWnd.bottom);
if (rectBorder.PtInRect (point))
{
return HTBOTTOM;
}
// bottom left
rectBorder.SetRect (rectWnd.left, rectWnd.bottom - nCursorHeight,
rectWnd.left + nCursorWidth, rectWnd.bottom);
if (rectBorder.PtInRect (point))
{
return HTBOTTOMLEFT;
}
// left
rectBorder.SetRect (rectWnd.left, rectWnd.top + nCursorHeight,
rectWnd.left + rectBorderSize.left, rectWnd.bottom - nCursorHeight);
if (rectBorder.PtInRect (point))
{
return HTLEFT;
}
}
else
{
// in sliding mode only one side enabled for sliding
UINT uEnabledSizingSide = 0;
// top border
rectBorder.SetRect (rectWnd.left, rectWnd.top, rectWnd.right,
rectWnd.top + rectBorderSize.top);
if (rectBorder.PtInRect (point))
{
if (uEnabledSizingSide != 0 && uEnabledSizingSide != HTTOP)
{
return HTBORDER; // no sizing
}
return HTTOP;
}
// left
rectBorder.SetRect (rectWnd.left, rectWnd.top,
rectWnd.left + rectBorderSize.left, rectWnd.bottom);
if (rectBorder.PtInRect (point))
{
if (uEnabledSizingSide != 0 && uEnabledSizingSide != HTLEFT)
{
return HTBORDER; // no sizing
}
return HTLEFT;
}
// bottom
rectBorder.SetRect (rectWnd.left, rectWnd.bottom - rectBorderSize.bottom,
rectWnd.right, rectWnd.bottom);
if (rectBorder.PtInRect (point))
{
if (uEnabledSizingSide != 0 && uEnabledSizingSide != HTBOTTOM)
{
return HTBORDER; // no sizing
}
return HTBOTTOM;
}
// right border
rectBorder.SetRect (rectWnd.right - rectBorderSize.right, rectWnd.top,
rectWnd.right, rectWnd.bottom);
if (rectBorder.PtInRect (point))
{
if (uEnabledSizingSide != 0 && uEnabledSizingSide != HTRIGHT)
{
return HTBORDER; // no sizing
}
return HTRIGHT;
}
}
return CWnd::OnNcHitTest(point);
}
//--------------------------------------------------------------------------------------//
BOOL CBCGPMiniFrameWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
switch (nHitTest)
{
case HTTOPLEFT:
case HTBOTTOMRIGHT:
SetCursor (AfxGetApp ()->LoadStandardCursor (IDC_SIZENWSE));
return TRUE;
case HTTOP:
case HTBOTTOM:
SetCursor (AfxGetApp ()->LoadStandardCursor (IDC_SIZENS));
return TRUE;
case HTRIGHT:
case HTLEFT:
SetCursor (AfxGetApp ()->LoadStandardCursor (IDC_SIZEWE));
return TRUE;
case HTTOPRIGHT:
case HTBOTTOMLEFT:
SetCursor (AfxGetApp ()->LoadStandardCursor (IDC_SIZENESW));
return TRUE;
}
return CWnd::OnSetCursor(pWnd, nHitTest, message);
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::OnSizing(UINT fwSide, LPRECT pRect)
{
CWnd::OnSizing(fwSide, pRect);
if (m_bRolledUp)
{
// can't be resized when rolled up
return;
}
CRect rectOldWnd;
GetWindowRect (rectOldWnd);
CBCGPTabbedToolbar* pTabbedBar = DYNAMIC_DOWNCAST (CBCGPTabbedToolbar, CWnd::FromHandlePermanent (m_hEmbeddedBar));
if (pTabbedBar != NULL)
{
*pRect = rectOldWnd;
// can't be resized when contains tabbed toolbar
return;
}
CRect rect (pRect);
CRect rectOldClient;
GetClientRect (rectOldClient);
BOOL bHorz = (fwSide == WMSZ_LEFT || fwSide == WMSZ_RIGHT);
if (bHorz && rect.Width () == rectOldWnd.Width () ||
!bHorz && rect.Height () == rectOldWnd.Height ())
{
return;
}
CBCGPToolBar* pNextBar = DYNAMIC_DOWNCAST (CBCGPToolBar, CWnd::FromHandlePermanent (m_hEmbeddedBar));
if (pNextBar == NULL)
{
return;
}
CRect rectBorderSize;
CalcBorderSize (rectBorderSize);
int nNewHeight = rect.Height () -
rectBorderSize.top - rectBorderSize.bottom - m_nCaptionHeight;
int nNewWidth = rect.Width () - rectBorderSize.left - rectBorderSize.right;
CSize sizeBarOld = pNextBar->CalcSize (FALSE);
CSize sizeBar =
pNextBar->StretchControlBar (bHorz ? nNewWidth : nNewHeight, !bHorz);
int nXBarDelta = sizeBar.cx - sizeBarOld.cx;
int nYBarDelta = sizeBar.cy - sizeBarOld.cy;
if (nXBarDelta == 0 && nYBarDelta == 0 && pNextBar->IsKindOf (RUNTIME_CLASS (CBCGPBaseToolBar)))
{
*pRect = rectOldWnd;
return;
}
if (nXBarDelta != 0)
{
if (fwSide == WMSZ_RIGHT)
{
pRect->right = pRect->left + rectOldWnd.Width () + nXBarDelta;
}
else
{
pRect->left = pRect->right - rectOldWnd.Width () - nXBarDelta;
}
}
else
{
fwSide == WMSZ_RIGHT ?
pRect->right = rectOldWnd.right : pRect->left = rectOldWnd.left;
}
if (nYBarDelta != 0)
{
if (fwSide == WMSZ_BOTTOM || fwSide == WMSZ_RIGHT || fwSide == WMSZ_LEFT)
{
pRect->bottom = pRect->top + rectOldWnd.Height() + nYBarDelta;
}
else
{
pRect->top = pRect->bottom - rectOldWnd.Height() - nYBarDelta;
}
}
else
{
fwSide == WMSZ_BOTTOM ?
pRect->bottom = rectOldWnd.bottom : pRect->top = rectOldWnd.top;
}
pNextBar->RecalcLayout ();
BOOL bParam = FALSE;
SystemParametersInfo (SPI_GETDRAGFULLWINDOWS, 0, &bParam, 0);
if (!bParam && pNextBar->IsKindOf (RUNTIME_CLASS (CBCGPBaseToolBar)))
{
SetWindowPos (NULL, pRect->left, pRect->top,
pRect->right - pRect->left, pRect->bottom - pRect->top,
SWP_NOZORDER | SWP_NOACTIVATE);
}
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
CBCGPControlBar* pBar = DYNAMIC_DOWNCAST (CBCGPControlBar, CWnd::FromHandlePermanent (m_hEmbeddedBar));
if (pBar != NULL)
{
pBar->RecalcLayout ();
}
CRect rect;
GetWindowRect (rect);
globalUtils.AdjustRectToWorkArea (rect);
SetWindowPos (NULL, rect.left, rect.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
ArrangeCaptionButtons ();
SendMessage (WM_NCPAINT);
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::SizeToContent ()
{
ASSERT_VALID (this);
CBCGPControlBar* pBar = DYNAMIC_DOWNCAST (CBCGPControlBar, CWnd::FromHandlePermanent (m_hEmbeddedBar));
if (pBar != NULL)
{
CSize sizeBar = pBar->CalcFixedLayout (FALSE, TRUE);
CRect rectWnd;
GetWindowRect (rectWnd);
CRect rectClient;
GetClientRect (rectClient);
int nXDelta = rectClient.Width () - sizeBar.cx;
int nYDelta = rectClient.Height () - sizeBar.cy;
SetWindowPos (NULL, 0, 0, rectWnd.Width () - nXDelta,
rectWnd.Height () - nYDelta,
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
}
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::OnBarRecalcLayout ()
{
CRect rect;
GetClientRect (&rect);
CBCGPControlBar* pBar = DYNAMIC_DOWNCAST (CBCGPControlBar, CWnd::FromHandlePermanent (m_hEmbeddedBar));
if (pBar != NULL)
{
pBar->SetWindowPos (NULL, rect.left, rect.top, rect.Width (), rect.Height (),
SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE);
pBar->RedrawWindow ();
}
}
//--------------------------------------------------------------------------------------//
BOOL CBCGPMiniFrameWnd::SetPreDockState (BCGP_PREDOCK_STATE preDockState,
CBCGPBaseControlBar* pBarToDock,
BCGP_DOCK_METHOD dockMethod)
{
if (preDockState == PDS_NOTHING ||
preDockState == PDS_DOCK_TO_TAB &&
pBarToDock != NULL &&
!pBarToDock->CanBeAttached ())
{
return TRUE;
}
if (pBarToDock != NULL && pBarToDock->GetParentMiniFrame () != NULL)
{
return TRUE;
}
BOOL bWasCaptured = m_bCaptured;
if (m_bCaptured)
{
ReleaseCapture ();
m_bCaptured = false;
OnCapture (FALSE);
}
CPoint ptScreen;
GetCursorPos (&ptScreen);
CPoint ptClientBar = ptScreen;
CBCGPDockingControlBar* pWnd = (CBCGPDockingControlBar*) GetControlBar ();
pWnd->ScreenToClient (&ptClientBar);
m_preDockStateCurr = preDockState;
m_pPreDockBar = DYNAMIC_DOWNCAST (CBCGPDockingControlBar, pBarToDock);
// it will be different bar in case
// of tab window
BOOL bWasDocked = FALSE;
CBCGPDockingControlBar* pDockedBar = DockControlBar (bWasDocked);
if (pDockedBar != NULL)
{
pDockedBar->AdjustDockingLayout ();
if (bWasCaptured)
{
pDockedBar->EnterDragMode (FALSE);
}
}
return FALSE;
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::OnMoveControlBar (CBCGPControlBar* /*pBar*/, CPoint ptOffset)
{
CRect rectMiniFrame;
GetWindowRect (rectMiniFrame);
rectMiniFrame.OffsetRect (ptOffset);
MoveWindow (rectMiniFrame);
}
//--------------------------------------------------------------------------------------//
void CBCGPMiniFrameWnd::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
lpwndpos->flags |= SWP_NOACTIVATE;
if ((lpwndpos->flags & SWP_NOMOVE) == 0)
{
CRect rectWnd;
GetWindowRect (&rectWnd);
CRect rect;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -