📄 bcgpcalendarbar.cpp
字号:
{
CRect rectButton (0, 0, 0, 0);
CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) m_Buttons.GetNext (pos);
ASSERT_VALID (pButton);
if (pButton->m_nStyle & TBBS_SEPARATOR)
{
if (bPrevSeparator)
{
rectButton.SetRectEmpty ();
}
else
{
// Next line
x = xDaysStart;
y = rectClient.top + m_sizeBox.cy;
rectButton = CRect (
CPoint (x, y),
CSize (rectClient.right - x, SEPARATOR_SIZE));
}
bPrevSeparator = TRUE;
}
else
{
if (pButton->IsKindOf (RUNTIME_CLASS (CCalendarWeekNumButton)))
{
CCalendarWeekNumButton* pCalendarButton = DYNAMIC_DOWNCAST (CCalendarWeekNumButton, pButton);
if (pCalendarButton == NULL)
{
continue;
}
ASSERT_VALID (pCalendarButton);
x = m_nHorzMargin / 2;
y = rectClient.top + SEPARATOR_SIZE + m_sizeBox.cy * (iWeekNo + 1) ;
rectButton = CRect (CPoint (x, y), CSize (nWeekBarWidth - m_nHorzMargin, m_sizeBox.cy));
bPrevSeparator = FALSE;
iWeekNo ++;
}
else if (pButton->IsKindOf (RUNTIME_CLASS (CCalendarTodayButton)))
{
CCalendarTodayButton* pCalendarButton = DYNAMIC_DOWNCAST (CCalendarTodayButton, pButton);
if (pCalendarButton == NULL)
{
continue;
}
ASSERT_VALID (pCalendarButton);
{
GetClientRect (&rectButton);
rectButton.DeflateRect(0, 0, rectButton.Width() - m_iTitleHeight + 1, rectButton.Height () - m_iTitleHeight + 1);
rectButton.DeflateRect(1, 1);
bPrevSeparator = FALSE;
}
}
else if (pButton->IsKindOf (RUNTIME_CLASS (CCalendarWeekButton)))
{
CCalendarWeekButton* pCalendarButton = DYNAMIC_DOWNCAST (CCalendarWeekButton, pButton);
if (pCalendarButton == NULL)
{
continue;
}
ASSERT_VALID (pCalendarButton);
{
x = xDaysStart + m_sizeBox.cx * (iWeekNum % 7);
y = rectClient.top;
rectButton = CRect (CPoint (x, y), m_sizeBox);
bPrevSeparator = FALSE;
}
iWeekNum ++;
}
else if (pButton->IsKindOf (RUNTIME_CLASS (CCalendarMonthButton)))
{
CCalendarMonthButton* pCalendarButton = DYNAMIC_DOWNCAST (CCalendarMonthButton, pButton);
if (pCalendarButton == NULL)
{
continue;
}
ASSERT_VALID (pCalendarButton);
{
pCalendarButton->m_strText = GetMonthName(m_dateSelected.GetMonth ());
CSize btnSize = pCalendarButton->ContextSize(this);
btnSize.cx += m_iTitleHeight;
GetClientRect (&rectButton);
rectButton.DeflateRect(0, 0, 0, rectButton.Height () - m_iTitleHeight + 1);
rectButton.DeflateRect((rectButton.Width () - btnSize.cx) / 2 + 1, 1);
bPrevSeparator = FALSE;
}
}
else if (pButton->IsKindOf (RUNTIME_CLASS (CCalendarNavigateButton)))
{
CCalendarNavigateButton* pCalendarButton = DYNAMIC_DOWNCAST (CCalendarNavigateButton, pButton);
iNavigate ++;
if (pCalendarButton == NULL)
{
continue;
}
ASSERT_VALID (pCalendarButton);
CSize btnSize (0, 0);
for(int i = 0; i < 12; i ++)
{
CString strMonth = GetMonthName (i + 1);
CSize textSize = dc.GetTextExtent(strMonth);
btnSize.cx = max(textSize.cx, btnSize.cx);
}
btnSize.cx += m_iTitleHeight;
GetClientRect (&rectButton);
rectButton.DeflateRect(0, 0, 0, rectButton.Height () - m_iTitleHeight + 1);
rectButton.DeflateRect((rectButton.Width () - btnSize.cx) / 2 + 1, 2);
switch(iNavigate)
{
case 1:
{
rectButton.OffsetRect (- rectButton.Height () * 2, 0);
}
break;
case 2:
{
rectButton.OffsetRect (- rectButton.Height (), 0);
}
break;
case 3:
{
rectButton.OffsetRect (rectButton.Width (), 0 );
}
break;
case 4:
{
rectButton.OffsetRect (rectButton.Width () + rectButton.Height (), 0);
}
break;
}
rectButton.right = rectButton.left + rectButton.Height ();
bPrevSeparator = FALSE;
}
else if (pButton->IsKindOf (RUNTIME_CLASS (CBCGPCalendarButton)))
{
CBCGPCalendarButton* pCalendarButton = DYNAMIC_DOWNCAST (CBCGPCalendarButton, pButton);
if (pCalendarButton == NULL)
{
continue;
}
ASSERT_VALID (pCalendarButton);
x = xDaysStart + m_sizeBox.cx * (iDayNum % 7);
y = rectClient.top + SEPARATOR_SIZE + m_sizeBox.cy * (iDayNum / 7 + 1) ;
rectButton = CRect (
CPoint (x, y), m_sizeBox);
bPrevSeparator = FALSE;
iDayNum ++;
}
}
pButton->SetRect (rectButton);
}
dc.SelectObject (pPrevFont);
UpdateTooltips ();
}
//***************************************************************************************
CSize CBCGPCalendarBar::CalcSize (BOOL /*bVertDock*/)
{
// Calculate caption width:
CClientDC dc (this);
CFont* pOldFont = dc.SelectObject (&globalData.fontRegular);
int nMonthMaxWidth = 0;
for(int i = 0; i < 12; i ++)
{
CString strMonth = GetMonthName (i + 1);
nMonthMaxWidth = max (dc.GetTextExtent(strMonth).cx, nMonthMaxWidth);
}
CString strYear = _T("0000");
int nYearWidth = dc.GetTextExtent(strYear).cx;
dc.SelectObject (pOldFont);
return CSize(
max (nMonthMaxWidth + 4 * m_sizeBox.cx + nYearWidth, 8 * m_sizeBox.cx) + 2 * m_nVertMargin,
7 * (m_sizeBox.cy + 2) + 2 * m_nHorzMargin +
SEPARATOR_SIZE + m_iTitleHeight);
}
//*************************************************************************************
CSize CBCGPCalendarBar::GetCalendarGridSize (BOOL bVertDock) const
//
// Calculate number of columns and rows in the grid
//
{
int nNumColumns = 7;
int nNumRows = 7;
return CSize (nNumColumns, nNumRows);
}
//**************************************************************************************
int CBCGPCalendarBar::GetExtraHeight (int nNumColumns) const
{
int nExtraHeight = 0;
return nExtraHeight;
}
BEGIN_MESSAGE_MAP(CBCGPCalendarBar, CBCGPPopupMenuBar)
//{{AFX_MSG_MAP(CBCGPCalendarBar)
ON_WM_CREATE()
ON_WM_NCCALCSIZE()
ON_WM_NCPAINT()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDBLCLK()
ON_WM_DESTROY()
ON_WM_TIMER()
ON_WM_MOUSEACTIVATE()
ON_WM_SIZE()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBCGPCalendarBar message handlers
void CBCGPCalendarBar::ContextToSize ()
{
ASSERT (GetSafeHwnd () != NULL);
m_nHorzOffset = GetMenuImageSize ().cx +
2 * CBCGPVisualManager::GetInstance ()->GetMenuImageMargin () + 1;
m_nVertOffset = 0;
CRect rectClient;
GetClientRect (rectClient);
rectClient.top += m_iTitleHeight;
rectClient.left += m_nHorzOffset;
m_sizeBox.cx = rectClient.Width () / 7 - 1;
m_sizeBox.cy = (rectClient.Height () - SEPARATOR_SIZE) / 7 - 1;
m_sizeBox.cx = max (m_sizeBox.cx, m_sizeBoxMin.cx);
m_sizeBox.cy = max (m_sizeBox.cy, m_sizeBoxMin.cy);
AdjustLocations ();
SetWindowPos (&wndTop, -1, -1, -1, -1,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
}
//**************************************************************************************
void CBCGPCalendarBar::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
{
if (m_bIsCtrl)
{
if (GetStyle() & WS_BORDER)
{
lpncsp->rgrc[0].left++;
lpncsp->rgrc[0].top++ ;
lpncsp->rgrc[0].right--;
lpncsp->rgrc[0].bottom--;
}
return;
}
if (m_bIsTearOff)
{
CBCGPToolBar::OnNcCalcSize(bCalcValidRects, lpncsp);
}
else
{
CBCGPPopupMenuBar::OnNcCalcSize(bCalcValidRects, lpncsp);
}
}
//**************************************************************************************
void CBCGPCalendarBar::OnNcPaint()
{
if (m_bIsCtrl)
{
if (GetStyle () & WS_BORDER)
{
CBCGPVisualManager::GetInstance ()->OnDrawControlBorder (this);
}
return;
}
if (m_bIsTearOff)
{
CBCGPToolBar::OnNcPaint();
}
else
{
CBCGPPopupMenuBar::OnNcPaint();
}
}
//**************************************************************************************
int CBCGPCalendarBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CBCGPPopupMenuBar::OnCreate(lpCreateStruct) == -1)
return -1;
const CSize sizeNavImage (10, 10);
const int nImageMargin = 2;
// Load navigation images:
{
SetLockedSizes (sizeNavImage + CSize (nImageMargin, nImageMargin), sizeNavImage);
CBCGPLocalResource lr;
BOOL bIsLoaded = LoadBitmap (IDB_BCGBARRES_CALENDAR, 0, 0, TRUE);
ASSERT (bIsLoaded);
}
m_sizeBox = sizeNavImage;
m_bLeaveFocus = (lpCreateStruct->style & WS_TABSTOP) == 0;
CClientDC dc (this);
CFont* pOldFont = dc.SelectObject (&globalData.fontRegular);
ASSERT (pOldFont != NULL);
int year = m_dateSelected.GetYear();
int month = m_dateSelected.GetMonth();
CBCGPDefaultLocale dl;
CString strDay = _T(" 99");
CSize textSize = dc.GetTextExtent(strDay);
m_sizeBox.cx = max (textSize.cx, m_sizeBox.cx);
m_sizeBox.cy = max (textSize.cy, m_sizeBox.cy);
for (int i = 1; i <= 7; i ++)
{
COleDateTime dt(year, month, i, 0, 0, 0);
CString strWeekday = dt.Format(_T("%a"));
textSize = dc.GetTextExtent(strWeekday);
m_sizeBox.cx = max (textSize.cx, m_sizeBox.cx);
m_sizeBox.cy = max (textSize.cy, m_sizeBox.cy);
}
if (pOldFont != NULL)
{
dc.SelectObject (pOldFont);
}
m_sizeBox.cx += nImageMargin;
m_sizeBox.cy += nImageMargin;
m_sizeBoxMin = m_sizeBox;
Rebuild ();
AdjustLocations();
if (m_pParentBtn != NULL)
{
SetCapture ();
SelectDay(m_dateSelected, FALSE, FALSE);
}
else
{
m_LastAddedDate = COleDateTime::GetCurrentTime();
}
return 0;
}
//*************************************************************************************
void CBCGPCalendarBar::Rebuild ()
{
if (GetSafeHwnd () == NULL)
{
return;
}
RemoveAllButtons ();
InsertButton (
new CCalendarTodayButton(4));
InsertButton (
CCalendarMonthButton());
if (m_styleFlags & CBCGPCalendarBar::CBR_NAVIGATION_BUTTONS)
for(int i = 0; i < 4; i ++)
InsertButton (
new CCalendarNavigateButton(i));
//TODO: Insert 7 weeks and 42 days of calendar
for (int i = 0; i < 7; i ++)
{
InsertButton (
new CCalendarWeekButton ());
}
if (m_styleFlags & CBCGPCalendarBar::CBR_WEEKNUMBER)
for (i = 0; i < 6; i ++)
{
InsertButton (
new CCalendarWeekNumButton ());
}
InsertSeparator ();
for (i = 0; i < 42; i ++)
{
InsertButton (
new CBCGPCalendarButton ());
}
SetDate (m_dateSelected);
}
class CBCGPCalendarCCmdUI : public CCmdUI
{
public:
CBCGPCalendarCCmdUI();
public: // re-implementations only
virtual void Enable(BOOL bOn);
BOOL m_bEnabled;
};
CBCGPCalendarCCmdUI::CBCGPCalendarCCmdUI()
{
m_bEnabled = TRUE; // assume it is enabled
}
//*************************************************************************************
void CBCGPCalendarCCmdUI::Enable(BOOL bOn)
{
m_bEnabled = bOn;
m_bEnableChanged = TRUE;
}
//*************************************************************************************
void CBCGPCalendarBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
{
ASSERT_VALID (this);
if (m_nCommandID == 0 || m_nCommandID == (UINT)-1)
{
CBCGPPopupMenuBar::OnUpdateCmdUI (pTarget, bDisableIfNoHndler);
return;
}
CBCGPCalendarCCmdUI state;
state.m_pOther = this;
state.m_nIndexMax = 1;
state.m_nID = m_nCommandID;
BOOL bIsEnabled = FALSE;
if (pTarget->OnCmdMsg (m_nCommandID, CN_UPDATE_COMMAND_UI, &state, NULL))
{
bIsEnabled = state.m_bEnabled;
}
else if (bDisableIfNoHndler && !state.m_bEnableChanged)
{
AFX_CMDHANDLERINFO info;
info.pTarget = NULL;
bIsEnabled = pTarget->OnCmdMsg (m_nCommandID, CN_COMMAND, &state, &info);
}
if (bIsEnabled != m_bIsEnabled)
{
m_bIsEnabled = bIsEnabled;
for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL;)
{
CBCGPCalendarButton* pCalendarButton = DYNAMIC_DOWNCAST (CBCGPCalendarButton, m_Buttons.GetNext (pos));
if (pCalendarButton != NULL)
{
pCalendarButton->m_nStyle &= ~TBBS_DISABLED;
if (!bIsEnabled)
{
pCalendarButton->m_nStyle |= TBBS_DISABLED;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -