📄 bcgpstatusbar.cpp
字号:
CBCGStatusBarPaneInfo* pSBP = _GetPanePtr(nIndex);
if (pSBP == NULL)
{
ASSERT (FALSE);
return;
}
if (++pSBP->nCurrFrame >= pSBP->nFrameCount)
{
pSBP->nCurrFrame = 0;
}
CRect rect = pSBP->rect;
if (!(pSBP->nStyle & SBPS_NOBORDERS))
rect.InflateRect(-CX_BORDER, -CY_BORDER);
else
rect.top -= CY_BORDER; // base line adjustment
rect.right = rect.left + pSBP->cxIcon;
InvalidateRect(rect, FALSE);
UpdateWindow ();
ClientToScreen (&rect);
CBCGPPopupMenu::UpdateAllShadows (rect);
}
//**********************************************************************************
UINT CBCGPStatusBar::OnNcHitTest(CPoint point)
{
// hit test the size box - convert to HTCAPTION if so
if (m_cxSizeBox != 0)
{
CRect rect;
GetClientRect(rect);
CalcInsideRect(rect, TRUE);
int cxMax = min(m_cxSizeBox-1, rect.Height());
rect.left = rect.right - cxMax;
ClientToScreen(&rect);
if (rect.PtInRect(point))
return HTBOTTOMRIGHT;
}
return CBCGPControlBar::OnNcHitTest(point);
}
//*******************************************************************************
void CBCGPStatusBar::OnSysCommand(UINT nID, LPARAM lParam)
{
if (!m_cxSizeBox != 0 && (nID & 0xFFF0) == SC_SIZE)
{
CFrameWnd* pFrameWnd = BCGPGetParentFrame(this);
if (pFrameWnd != NULL)
{
pFrameWnd->SendMessage(WM_SYSCOMMAND, (WPARAM)nID, lParam);
return;
}
}
CBCGPControlBar::OnSysCommand(nID, lParam);
}
//*******************************************************************************
void CBCGPStatusBar::OnSize(UINT nType, int cx, int cy)
{
CBCGPControlBar::OnSize(nType, cx, cy);
RecalcLayout ();
// force repaint on resize (recalculate stretchy)
Invalidate();
UpdateWindow ();
}
//*******************************************************************************
LRESULT CBCGPStatusBar::OnSetFont(WPARAM wParam, LPARAM lParam)
{
m_hFont = (HFONT)wParam;
ASSERT(m_hFont != NULL);
RecalcLayout ();
if ((BOOL)lParam)
{
Invalidate();
UpdateWindow ();
}
return 0L; // does not re-draw or invalidate - resize parent instead
}
//*******************************************************************************
LRESULT CBCGPStatusBar::OnGetFont(WPARAM, LPARAM)
{
HFONT hFont = GetCurrentFont ();
return (LRESULT)(UINT)hFont;
}
//*******************************************************************************
LRESULT CBCGPStatusBar::OnSetText(WPARAM, LPARAM lParam)
{
int nIndex = CommandToIndex(0);
if (nIndex < 0)
return -1;
return SetPaneText(nIndex, (LPCTSTR)lParam) ? 0 : -1;
}
//*******************************************************************************
LRESULT CBCGPStatusBar::OnGetText(WPARAM wParam, LPARAM lParam)
{
int nMaxLen = (int)wParam;
if (nMaxLen == 0)
return 0; // nothing copied
LPTSTR lpszDest = (LPTSTR)lParam;
int nLen = 0;
int nIndex = CommandToIndex(0); // use pane with ID zero
if (nIndex >= 0)
{
CBCGStatusBarPaneInfo* pSBP = _GetPanePtr(nIndex);
if (pSBP == NULL)
{
ASSERT (FALSE);
return 0;
}
nLen = pSBP->lpszText != NULL ? lstrlen(pSBP->lpszText) : 0;
if (nLen > nMaxLen)
nLen = nMaxLen - 1; // number of characters to copy (less term.)
memcpy(lpszDest, pSBP->lpszText, nLen*sizeof(TCHAR));
}
lpszDest[nLen] = '\0';
return nLen+1; // number of bytes copied
}
//*******************************************************************************
LRESULT CBCGPStatusBar::OnGetTextLength(WPARAM, LPARAM)
{
int nLen = 0;
int nIndex = CommandToIndex(0); // use pane with ID zero
if (nIndex >= 0)
{
CBCGStatusBarPaneInfo* pSBP = _GetPanePtr(nIndex);
if (pSBP == NULL)
{
ASSERT (FALSE);
return 0;
}
if (pSBP->lpszText != NULL)
{
nLen = lstrlen(pSBP->lpszText);
}
}
return nLen;
}
//*******************************************************************************
void CBCGPStatusBar::OnDrawPane (CDC* pDC, CBCGStatusBarPaneInfo* pPane)
{
ASSERT_VALID (pDC);
ASSERT (pPane != NULL);
CRect rectPane = pPane->rect;
if (rectPane.IsRectEmpty () || !pDC->RectVisible (rectPane))
{
return;
}
// Draw pane border:
CBCGPVisualManager::GetInstance ()->OnDrawStatusBarPaneBorder (pDC, this,
rectPane, pPane->nID, pPane->nStyle);
if (!(pPane->nStyle & SBPS_NOBORDERS)) // only adjust if there are borders
{
rectPane.DeflateRect (2 * CX_BORDER, CY_BORDER);
}
// Draw icon
if (pPane->hImage != NULL && pPane->cxIcon > 0)
{
CRect rectIcon = rectPane;
rectIcon.right = rectIcon.left + pPane->cxIcon;
int x = max (0, (rectIcon.Width () - pPane->cxIcon) / 2);
int y = max (0, (rectIcon.Height () - pPane->cyIcon) / 2);
::ImageList_DrawEx (pPane->hImage, pPane->nCurrFrame, pDC->GetSafeHdc (),
rectIcon.left + x, rectIcon.top + y,
pPane->cxIcon, pPane->cyIcon, CLR_NONE, 0, ILD_NORMAL);
}
CRect rectText = rectPane;
rectText.left += pPane->cxIcon;
if (pPane->cxIcon > 0)
{
rectText.left += nTextMargin;
}
if (pPane->nProgressTotal > 0)
{
// Draw progress bar:
CRect rectProgress = rectText;
rectProgress.DeflateRect (1, 1);
COLORREF clrBar = (pPane->clrProgressBar == (COLORREF)-1) ?
globalData.clrHilite : pPane->clrProgressBar;
CBCGPVisualManager::GetInstance ()->OnDrawStatusBarProgress (pDC, this,
rectProgress, pPane->nProgressTotal, pPane->nProgressCurr,
clrBar, pPane->clrProgressBarDest, pPane->clrProgressText,
pPane->bProgressText);
}
else
{
// Draw text
if (pPane->lpszText != NULL && pPane->cxText > 0)
{
COLORREF clrText = pDC->SetTextColor ((pPane->nStyle & SBPS_DISABLED) ?
globalData.clrGrayedText :
pPane->clrText == (COLORREF)-1 ?
globalData.clrBtnText : pPane->clrText);
pDC->DrawText (pPane->lpszText, lstrlen(pPane->lpszText), rectText,
DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX);
pDC->SetTextColor (clrText);
}
}
}
//**********************************************************************************
void CBCGPStatusBar::RecalcLayout ()
{
ASSERT_VALID (this);
ASSERT (GetSafeHwnd () != NULL);
// get the drawing area for the status bar
CRect rect;
GetClientRect(rect);
CalcInsideRect(rect, TRUE);
// the size box is based off the size of a scrollbar
m_cxSizeBox = min(GetSystemMetrics(SM_CXVSCROLL)+1, rect.Height());
CFrameWnd* pFrameWnd = BCGPGetParentFrame(this);
if (pFrameWnd != NULL && pFrameWnd->IsZoomed())
{
m_cxSizeBox = 0;
}
if ((GetStyle() & SBARS_SIZEGRIP) == 0)
{
m_cxSizeBox = 0;
}
CClientDC dcScreen (NULL);
int xMax = (rect.right -= m_cxSizeBox);
if (m_cxSizeBox == 0)
xMax += m_cxRightBorder + 1;
// walk through to calculate extra space
int cxExtra = rect.Width() + m_cxDefaultGap;
CBCGStatusBarPaneInfo* pSBP = (CBCGStatusBarPaneInfo*)m_pData;
for (int i = 0; i < m_nCount; i++, pSBP++)
{
cxExtra -= (pSBP->cxText + pSBP->cxIcon + CX_BORDER * 4 + m_cxDefaultGap);
if (pSBP->cxText > 0 && pSBP->cxIcon > 0)
{
cxExtra -= nTextMargin;
}
}
// if cxExtra <= 0 then we will not stretch but just clip
for (i = 0, pSBP = (CBCGStatusBarPaneInfo*)m_pData; i < m_nCount; i++, pSBP++)
{
ASSERT(pSBP->cxText >= 0);
ASSERT(pSBP->cxIcon >= 0);
if (rect.left >= xMax)
{
pSBP->rect = CRect (0, 0, 0, 0);
}
else
{
int cxPane = pSBP->cxText + pSBP->cxIcon;
if (pSBP->cxText > 0 && pSBP->cxIcon > 0)
{
cxPane += nTextMargin;
}
if ((pSBP->nStyle & SBPS_STRETCH) && cxExtra > 0)
{
cxPane += cxExtra;
cxExtra = 0;
}
rect.right = rect.left + cxPane + CX_BORDER * 4;
rect.right = min(rect.right, xMax);
pSBP->rect = rect;
rect.left = rect.right + m_cxDefaultGap;
}
}
if (m_cxSizeBox != 0)
{
int cxMax = min(m_cxSizeBox, rect.Height()+m_cyTopBorder);
m_rectSizeBox = rect;
m_rectSizeBox.left = rect.right;
m_rectSizeBox.right = m_rectSizeBox.left + cxMax;
}
else
{
m_rectSizeBox.SetRectEmpty ();
}
}
/////////////////////////////////////////////////////////////////////////////
// CBCGPStatusBar idle update through CBCGStatusCmdUI class
class CBCGStatusCmdUI : public CCmdUI // class private to this file!
{
public: // re-implementations only
virtual void Enable(BOOL bOn);
virtual void SetCheck(int nCheck);
virtual void SetText(LPCTSTR lpszText);
};
void CBCGStatusCmdUI::Enable(BOOL bOn)
{
m_bEnableChanged = TRUE;
CBCGPStatusBar* pStatusBar = (CBCGPStatusBar*)m_pOther;
ASSERT(pStatusBar != NULL);
ASSERT_KINDOF(CBCGPStatusBar, pStatusBar);
ASSERT(m_nIndex < m_nIndexMax);
UINT nNewStyle = pStatusBar->GetPaneStyle(m_nIndex) & ~SBPS_DISABLED;
if (!bOn)
nNewStyle |= SBPS_DISABLED;
pStatusBar->SetPaneStyle(m_nIndex, nNewStyle);
}
//*******************************************************************************
void CBCGStatusCmdUI::SetCheck(int nCheck) // "checking" will pop out the text
{
CBCGPStatusBar* pStatusBar = (CBCGPStatusBar*)m_pOther;
ASSERT(pStatusBar != NULL);
ASSERT_KINDOF(CBCGPStatusBar, pStatusBar);
ASSERT(m_nIndex < m_nIndexMax);
UINT nNewStyle = pStatusBar->GetPaneStyle(m_nIndex) & ~SBPS_POPOUT;
if (nCheck != 0)
nNewStyle |= SBPS_POPOUT;
pStatusBar->SetPaneStyle(m_nIndex, nNewStyle);
}
//*******************************************************************************
void CBCGStatusCmdUI::SetText(LPCTSTR lpszText)
{
ASSERT(m_pOther != NULL);
ASSERT_KINDOF(CBCGPStatusBar, m_pOther);
ASSERT(m_nIndex < m_nIndexMax);
((CBCGPStatusBar*)m_pOther)->SetPaneText(m_nIndex, lpszText);
}
//*******************************************************************************
void CBCGPStatusBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
{
CBCGStatusCmdUI state;
state.m_pOther = this;
state.m_nIndexMax = (UINT)m_nCount;
for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
state.m_nIndex++)
{
state.m_nID = _GetPanePtr(state.m_nIndex)->nID;
state.DoUpdate(pTarget, bDisableIfNoHndler);
}
// update the dialog controls added to the status bar
UpdateDialogControls(pTarget, bDisableIfNoHndler);
}
//*************************************************************************************
int CBCGPStatusBar::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
{
ASSERT_VALID(this);
// check child windows first by calling CBCGPControlBar
int nHit = CBCGPControlBar::OnToolHitTest(point, pTI);
if (nHit != -1)
return nHit;
CBCGStatusBarPaneInfo* pSBP = HitTest (point);
if (pSBP != NULL && pSBP->lpszToolTip != NULL)
{
nHit = pSBP->nID;
if (pTI != NULL)
{
CString strTipText = pSBP->lpszToolTip;
pTI->lpszText = (LPTSTR) ::calloc ((strTipText.GetLength () + 1), sizeof (TCHAR));
_tcscpy (pTI->lpszText, strTipText);
pTI->rect = pSBP->rect;
pTI->uId = 0;
pTI->hwnd = m_hWnd;
}
}
#if _MSC_VER >= 1300
CToolTipCtrl* pToolTip = AfxGetModuleState()->m_thread.GetDataNA()->m_pToolTip;
#else
_AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
CToolTipCtrl* pToolTip = pThreadState->m_pToolTip;
#endif
if (pToolTip != NULL && pToolTip->GetSafeHwnd () != NULL)
{
pToolTip->SetFont (&globalData.fontTooltip, FALSE);
}
return nHit;
}
//****************************************************************************************
CBCGStatusBarPaneInfo* CBCGPStatusBar::HitTest (CPoint pt) const
{
ASSERT_VALID (this);
for (int i = 0; i < m_nCount; i++)
{
CBCGStatusBarPaneInfo* pSBP = _GetPanePtr(i);
ASSERT (pSBP != NULL);
CRect rect = pSBP->rect;
if (rect.PtInRect (pt))
{
return pSBP;
}
}
return NULL;
}
//****************************************************************************************
long CBCGPStatusBar::GetPaneProgress (int nIndex) const
{
ASSERT_VALID(this);
CBCGStatusBarPaneInfo* pSBP = _GetPanePtr(nIndex);
if (pSBP == NULL)
{
ASSERT (FALSE);
return -1;
}
return pSBP->nProgressCurr;
}
//**************************************************************************************
HFONT CBCGPStatusBar::GetCurrentFont () const
{
return m_hFont == NULL ?
(HFONT) globalData.fontRegular.GetSafeHandle () :
m_hFont;
}
//***************************************************************************************
LRESULT CBCGPStatusBar::OnStyleChanged(WPARAM wp, LPARAM lp)
{
int nStyleType = (int) wp;
LPSTYLESTRUCT lpStyleStruct = (LPSTYLESTRUCT) lp;
CBCGPControlBar::OnStyleChanged (nStyleType, lpStyleStruct);
if ((lpStyleStruct->styleNew & SBARS_SIZEGRIP) &&
(lpStyleStruct->styleOld & SBARS_SIZEGRIP) == 0)
{
RecalcLayout ();
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// CBCGPStatusBar diagnostics
#ifdef _DEBUG
void CBCGPStatusBar::AssertValid() const
{
CBCGPControlBar::AssertValid();
}
//********************************************************************************
void CBCGPStatusBar::Dump(CDumpContext& dc) const
{
CBCGPControlBar::Dump(dc);
dc << "\nm_hFont = " << (UINT)m_hFont;
if (dc.GetDepth() > 0)
{
for (int i = 0; i < m_nCount; i++)
{
dc << "\nstatus pane[" << i << "] = {";
dc << "\n\tnID = " << _GetPanePtr(i)->nID;
dc << "\n\tnStyle = " << _GetPanePtr(i)->nStyle;
dc << "\n\tcxText = " << _GetPanePtr(i)->cxText;
dc << "\n\tcxIcon = " << _GetPanePtr(i)->cxIcon;
dc << "\n\tlpszText = " << _GetPanePtr(i)->lpszText;
dc << "\n\t}";
}
}
dc << "\n";
}
#endif //_DEBUG
#undef new
#ifdef AFX_INIT_SEG
#pragma code_seg(AFX_INIT_SEG)
#endif
IMPLEMENT_DYNAMIC(CBCGPStatusBar, CBCGPControlBar)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -