📄 bcgptoolbardatetimectrl.cpp
字号:
{
CBCGPToolbarDateTimeCtrl* pDateTime =
DYNAMIC_DOWNCAST (CBCGPToolbarDateTimeCtrl, listButtons.GetNext (posCombo));
ASSERT (pDateTime != NULL);
if (pDateTime != this)
{
pDateTime->m_pWndDateTime->SetTime (m_dwTimeStatus == GDT_VALID? &m_time : NULL);
}
}
}
}
return TRUE;
}
return TRUE;
}
#pragma warning (default : 4310)
//**************************************************************************************
void CBCGPToolbarDateTimeCtrl::OnAddToCustomizePage ()
{
CObList listButtons; // Existing buttons with the same command ID
if (CBCGPToolBar::GetCommandButtons (m_nID, listButtons) == 0)
{
return;
}
CBCGPToolbarDateTimeCtrl* pOther =
(CBCGPToolbarDateTimeCtrl*) listButtons.GetHead ();
ASSERT_VALID (pOther);
ASSERT_KINDOF (CBCGPToolbarDateTimeCtrl, pOther);
CopyFrom (*pOther);
}
//**************************************************************************************
HBRUSH CBCGPToolbarDateTimeCtrl::OnCtlColor (CDC* pDC, UINT /*nCtlColor*/)
{
pDC->SetTextColor (globalData.clrWindowText);
pDC->SetBkColor (globalData.clrWindow);
return (HBRUSH) globalData.brWindow.GetSafeHandle ();
}
//**************************************************************************************
void CBCGPToolbarDateTimeCtrl::OnDraw (CDC* pDC, const CRect& rect, CBCGPToolBarImages* pImages,
BOOL bHorz, BOOL bCustomizeMode,
BOOL bHighlight,
BOOL bDrawBorder, BOOL bGrayDisabledButtons)
{
if (m_pWndDateTime->GetSafeHwnd () == NULL ||
(m_pWndDateTime->GetStyle () & WS_VISIBLE) == 0)
{
CBCGPToolbarButton::OnDraw (pDC, rect, pImages,
bHorz, bCustomizeMode,
bHighlight, bDrawBorder, bGrayDisabledButtons);
}
else if ((m_bTextBelow && bHorz) && !m_strText.IsEmpty())
{
//-----------------------------------
// Draw button's text - Guy Hachlili:
//-----------------------------------
BOOL bDisabled = (bCustomizeMode && !IsEditable ()) ||
(!bCustomizeMode && (m_nStyle & TBBS_DISABLED));
pDC->SetTextColor (bDisabled ?
globalData.clrGrayedText :
(bHighlight) ? CBCGPToolBar::GetHotTextColor () :
globalData.clrBarText);
CRect rectText;
rectText.left = (rect.left + rect.right - m_sizeText.cx) / 2;
rectText.right = (rect.left + rect.right + m_sizeText.cx) / 2;
rectText.top = rect.bottom + rect.top;
rectText.bottom = rectText.top + m_sizeText.cy;
pDC->DrawText (m_strText, &rectText, DT_CENTER | DT_WORDBREAK);
}
}
//**************************************************************************************
BOOL CBCGPToolbarDateTimeCtrl::OnClick (CWnd* /*pWnd*/, BOOL /*bDelay*/)
{
return m_pWndDateTime->GetSafeHwnd () != NULL &&
(m_pWndDateTime->GetStyle () & WS_VISIBLE);
}
//******************************************************************************************
int CBCGPToolbarDateTimeCtrl::OnDrawOnCustomizeList (
CDC* pDC, const CRect& rect, BOOL bSelected)
{
int iWidth = CBCGPToolbarButton::OnDrawOnCustomizeList (pDC, rect, bSelected);
//------------------------------
// Simulate DateTimeCtrl appearance:
//------------------------------
CRect rectDateTime = rect;
int iDateTimeWidth = rect.Width () - iWidth;
if (iDateTimeWidth < 20)
{
iDateTimeWidth = 20;
}
rectDateTime.left = rectDateTime.right - iDateTimeWidth;
rectDateTime.DeflateRect (2, 3);
pDC->FillSolidRect (rectDateTime, globalData.clrWindow);
pDC->Draw3dRect (&rectDateTime,
globalData.clrBarDkShadow,
globalData.clrBarHilite);
rectDateTime.DeflateRect (1, 1);
pDC->Draw3dRect (&rectDateTime,
globalData.clrBarShadow,
globalData.clrBarLight);
CRect rectBtn = rectDateTime;
rectBtn.left = rectBtn.right - rectBtn.Height ();
rectBtn.DeflateRect (1, 1);
pDC->FillSolidRect (rectBtn, globalData.clrBarFace);
pDC->Draw3dRect (&rectBtn,
globalData.clrBarHilite,
globalData.clrBarDkShadow);
CPoint pointTriangle (
rectBtn.left + (rectBtn.Width () - CMenuImages::Size ().cx) / 2,
rectBtn.top + (rectBtn.Height () - CMenuImages::Size ().cy) / 2);
CMenuImages::Draw (pDC, CMenuImages::IdArowDown, pointTriangle);
return rect.Width ();
}
//********************************************************************************************
CBCGPDateTimeCtrlWin* CBCGPToolbarDateTimeCtrl::CreateDateTimeCtrl (CWnd* pWndParent, const CRect& rect)
{
CBCGPDateTimeCtrlWin* pWndDateTime = new CBCGPDateTimeCtrlWin;
if (!pWndDateTime->Create (m_dwStyle, rect, pWndParent, m_nID))
{
delete pWndDateTime;
return NULL;
}
return pWndDateTime;
}
//****************************************************************************************
void CBCGPToolbarDateTimeCtrl::OnShow (BOOL bShow)
{
if (m_pWndDateTime->GetSafeHwnd () != NULL)
{
if (bShow && m_bHorz)
{
m_pWndDateTime->ShowWindow (SW_SHOWNOACTIVATE);
OnMove ();
}
else
{
m_pWndDateTime->ShowWindow (SW_HIDE);
}
}
}
//*************************************************************************************
BOOL CBCGPToolbarDateTimeCtrl::ExportToMenuButton (CBCGPToolbarMenuButton& menuButton) const
{
CString strMessage;
int iOffset;
if (strMessage.LoadString (m_nID) &&
(iOffset = strMessage.Find (_T('\n'))) != -1)
{
menuButton.m_strText = strMessage.Mid (iOffset + 1);
}
return TRUE;
}
//*************************************************************************************
BOOL CBCGPToolbarDateTimeCtrl::SetTime (LPSYSTEMTIME pTimeNew /* = NULL */)
{
BOOL bResult = m_pWndDateTime->SetTime (pTimeNew);
NotifyCommand (DTN_DATETIMECHANGE);
return bResult;
}
//*************************************************************************************
BOOL CBCGPToolbarDateTimeCtrl::SetTime (const COleDateTime& timeNew)
{
BOOL bResult = m_pWndDateTime->SetTime (timeNew);
NotifyCommand (DTN_DATETIMECHANGE);
return bResult;
}
//*************************************************************************************
BOOL CBCGPToolbarDateTimeCtrl::SetTime (const CTime* pTimeNew)
{
BOOL bResult = m_pWndDateTime->SetTime (pTimeNew);
NotifyCommand (DTN_DATETIMECHANGE);
return bResult;
}
//*********************************************************************************
CBCGPToolbarDateTimeCtrl* CBCGPToolbarDateTimeCtrl::GetByCmd (UINT uiCmd)
{
CBCGPToolbarDateTimeCtrl* pSrcDateTime = NULL;
CObList listButtons;
if (CBCGPToolBar::GetCommandButtons(uiCmd, listButtons) > 0)
{
for (POSITION posDateTime= listButtons.GetHeadPosition (); pSrcDateTime == NULL && posDateTime != NULL;)
{
CBCGPToolbarDateTimeCtrl* pDateTime= DYNAMIC_DOWNCAST(CBCGPToolbarDateTimeCtrl, listButtons.GetNext(posDateTime));
ASSERT (pDateTime != NULL);
pSrcDateTime = pDateTime;
}
}
return pSrcDateTime;
}
//*********************************************************************************
BOOL CBCGPToolbarDateTimeCtrl::SetTimeAll (UINT uiCmd, LPSYSTEMTIME pTimeNew /* = NULL */)
{
CBCGPToolbarDateTimeCtrl* pSrcDateTime = GetByCmd (uiCmd);
if (pSrcDateTime)
{
pSrcDateTime->SetTime (pTimeNew);
}
return pSrcDateTime != NULL;
}
//*********************************************************************************
BOOL CBCGPToolbarDateTimeCtrl::SetTimeAll (UINT uiCmd, const COleDateTime& timeNew)
{
CBCGPToolbarDateTimeCtrl* pSrcDateTime = GetByCmd (uiCmd);
if (pSrcDateTime)
{
pSrcDateTime->SetTime (timeNew);
}
return pSrcDateTime != NULL;
}
//*********************************************************************************
BOOL CBCGPToolbarDateTimeCtrl::SetTimeAll (UINT uiCmd, const CTime* pTimeNew)
{
CBCGPToolbarDateTimeCtrl* pSrcDateTime = GetByCmd (uiCmd);
if (pSrcDateTime)
{
pSrcDateTime->SetTime (pTimeNew);
}
return pSrcDateTime != NULL;
}
//*********************************************************************************
DWORD CBCGPToolbarDateTimeCtrl::GetTimeAll (UINT uiCmd, LPSYSTEMTIME pTimeDest)
{
CBCGPToolbarDateTimeCtrl* pSrcDateTime = GetByCmd (uiCmd);
if (pSrcDateTime)
{
return pSrcDateTime->GetTime (pTimeDest);
}
else
return GDT_NONE;
}
//*********************************************************************************
BOOL CBCGPToolbarDateTimeCtrl::GetTimeAll (UINT uiCmd, COleDateTime& timeDest)
{
CBCGPToolbarDateTimeCtrl* pSrcDateTime = GetByCmd (uiCmd);
if (pSrcDateTime)
{
return pSrcDateTime->GetTime (timeDest);
}
else
return FALSE;
}
//*********************************************************************************
DWORD CBCGPToolbarDateTimeCtrl::GetTimeAll (UINT uiCmd, CTime& timeDest)
{
CBCGPToolbarDateTimeCtrl* pSrcDateTime = GetByCmd (uiCmd);
if (pSrcDateTime)
{
return pSrcDateTime->GetTime (timeDest);
}
else
return GDT_NONE;
}
//*********************************************************************************
void CBCGPToolbarDateTimeCtrl::SetStyle (UINT nStyle)
{
CBCGPToolbarButton::SetStyle (nStyle);
if (m_pWndDateTime != NULL && m_pWndDateTime->GetSafeHwnd () != NULL)
{
BOOL bDisabled = (CBCGPToolBar::IsCustomizeMode () && !IsEditable ()) ||
(!CBCGPToolBar::IsCustomizeMode () && (m_nStyle & TBBS_DISABLED));
m_pWndDateTime->EnableWindow (!bDisabled);
}
}
//********************************************************************************
BOOL CBCGPToolbarDateTimeCtrl::OnUpdateToolTip (CWnd* pWndParent, int iButtonIndex,
CToolTipCtrl& wndToolTip, CString& strTipText)
{
if (!m_bHorz)
{
return FALSE;
}
CString strTips;
if (OnGetCustomToolTipText (strTips))
{
strTipText = strTips;
}
CDateTimeCtrl* pWndDate = GetDateTimeCtrl ();
if (pWndDate != NULL)
{
wndToolTip.AddTool (pWndDate, strTipText, NULL, 0);
return TRUE;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -