📄 bcgpcalendarbar.cpp
字号:
}
}
Invalidate ();
UpdateWindow ();
}
CBCGPPopupMenuBar::OnUpdateCmdUI (pTarget, bDisableIfNoHndler);
}
//*************************************************************************************
void CBCGPCalendarBar::OnFillBackground (CDC* pDC)
{
ASSERT_VALID (pDC);
CRect rectClient;
GetClientRect (rectClient);
CRect rectWeekColumn = rectClient;
rectWeekColumn.top += m_iTitleHeight;
rectWeekColumn.right = rectWeekColumn.left + CBCGPToolBar::GetMenuImageSize ().cx +
2 * CBCGPVisualManager::GetInstance ()->GetMenuImageMargin () + 1;
CBCGPVisualManager::GetInstance ()->OnFillCalendarBarWeekColumn (
pDC, rectWeekColumn, m_clrWeekText, m_clrWeekTextDisabled);
CRect rectNavRow = rectClient;
rectNavRow.bottom = rectClient.top + m_iTitleHeight;
m_clrNavButton = CBCGPVisualManager::GetInstance ()->OnFillCalendarBarNavigationRow
(pDC, rectNavRow);
int nOldBkMode = pDC->SetBkMode (TRANSPARENT);
COLORREF clrOldText = pDC->SetTextColor (m_clrNavButton);
CFont* pOldFont = pDC->SelectObject (&globalData.fontRegular);
CString strYear = m_dateSelected.Format(_T("%Y"));
rectNavRow.DeflateRect (m_nHorzMargin, 0);
pDC->DrawText (strYear, rectNavRow, DT_VCENTER | DT_RIGHT | DT_SINGLELINE);
pDC->SelectObject (pOldFont);
pDC->SetTextColor (clrOldText);
pDC->SetBkMode (nOldBkMode);
}
//*************************************************************************************
BOOL CBCGPCalendarBar::OnSendCommand (const CBCGPToolbarButton* pButton)
{
BOOL isCtrlPressed = (0x8000 & GetKeyState(VK_CONTROL)) != 0;
BOOL isShiftPressed = (0x8000 & GetKeyState(VK_SHIFT)) != 0;
COleDateTime date = COleDateTime::GetCurrentTime();
CBCGPCalendarMenuButton* pCalendarMenuButton = NULL;
CBCGPPopupMenu* pParentMenu = DYNAMIC_DOWNCAST (CBCGPPopupMenu, GetParent ());
if (pParentMenu != NULL)
{
pCalendarMenuButton = DYNAMIC_DOWNCAST (CBCGPCalendarMenuButton, pParentMenu->GetParentButton ());
}
LPARAM buttonKind = Click_NOWHERE;
CBCGPCalendarButton* pCalendarButton;
pCalendarButton = DYNAMIC_DOWNCAST (CCalendarNavigateButton, pButton);
if (pCalendarButton)
{
if (m_bIsTearOff)
SetDate(pCalendarButton->m_Calendar);
else
{
int iY = pCalendarButton->m_Calendar.GetYear();
int iM = pCalendarButton->m_Calendar.GetMonth();
int iD = m_dateSelected.GetDay ();
COleDateTime dateToSelect(iY, iM, 1, 0, 0, 0);
int iMaxDay = GetMaxMonthDay(dateToSelect);
if (iD > iMaxDay)
iD = iMaxDay;
SetDate(COleDateTime (iY, iM, iD, 0, 0, 0));
}
return TRUE;
}
else
{
pCalendarButton = DYNAMIC_DOWNCAST (CCalendarWeekButton, pButton);
if (pCalendarButton)
{
if (m_bIsTearOff
&& (m_styleFlags & CBCGPCalendarBar::CBR_MULTISELECTION) != 0
&& (m_styleFlags & CBCGPCalendarBar::CBR_WEEKDAYSEL) != 0)
{
buttonKind = Click_WEEKDAY;
SelectWeekday(pCalendarButton->m_Calendar, isCtrlPressed, isShiftPressed);
}
else
{
return TRUE;
}
}
else
{
pCalendarButton = DYNAMIC_DOWNCAST (CCalendarWeekNumButton, pButton);
if (pCalendarButton)
{
if (m_bIsTearOff
&& (m_styleFlags & CBCGPCalendarBar::CBR_MULTISELECTION) != 0
&& (m_styleFlags & CBCGPCalendarBar::CBR_WEEKNUMBER) != 0)
{
buttonKind = Click_WEEKNO;
CString str = pCalendarButton->m_Calendar.Format ();
SelectWeek(pCalendarButton->m_Calendar, isCtrlPressed, isShiftPressed);
}
else
{
return TRUE;
}
}
else
{
pCalendarButton = DYNAMIC_DOWNCAST (CBCGPCalendarButton, pButton);
if (!isCtrlPressed && !isShiftPressed)
buttonKind = Click_DAY;
if (pCalendarButton != NULL)
SelectDay(pCalendarButton->m_Calendar, isCtrlPressed, isShiftPressed);
}
}
}
if (pCalendarButton != NULL)
{
date = pCalendarButton->m_Calendar;
}
if (pCalendarMenuButton != NULL)
{
pCalendarMenuButton->SetDate (date);
InvokeMenuCommand (pCalendarMenuButton->m_nID, pCalendarMenuButton);
}
else if (m_pParentBtn != NULL)
{
m_pParentBtn->SetDate (date);
GetParent ()->PostMessage (WM_CLOSE);
}
else if (Click_DAY == buttonKind)
{
ASSERT (m_nCommandID != 0);
SetDate (date);
CObList listButtons;
if (CBCGPToolBar::GetCommandButtons (m_nCommandID, listButtons) > 0)
{
for (POSITION pos = listButtons.GetHeadPosition (); pos != NULL;)
{
CBCGPCalendarMenuButton* pButton =
DYNAMIC_DOWNCAST (CBCGPCalendarMenuButton, listButtons.GetNext (pos));
if (pButton != NULL)
{
pButton->SetDate (date, FALSE);
}
}
}
CBCGPCalendarMenuButton::SetCalendarByCmdID (m_nCommandID, date);
GetOwner()->SendMessage (WM_COMMAND, m_nCommandID); // send command
if (BCGCBProGetTopLevelFrame (this) != NULL)
{
BCGCBProGetTopLevelFrame (this)->SetFocus ();
}
}
return TRUE;
}
//*************************************************************************************
BOOL CBCGPCalendarBar::Create(
CWnd* pParentWnd,
DWORD dwStyle,
UINT nID,
BOOL enableSelection)
{
if (enableSelection)
{
m_styleFlags |= CBR_MULTISELECTION;
}
else
{
m_styleFlags &= (~CBR_MULTISELECTION);
}
//TODO: calc from max(textheight and menuimageHeight)
//m_iTitleHeight = GetSystemMetrics(SM_CYCAPTION);
return CBCGPPopupMenuBar::Create (pParentWnd, dwStyle, nID);
}
//************************************************************************************
BOOL CBCGPCalendarBar::CreateControl (
CWnd* pParentWnd,
const CRect& rect,
UINT nID,
BOOL enableSelection,
DWORD dwStyle)
{
ASSERT_VALID (pParentWnd);
EnableLargeIcons (FALSE);
if (!Create (pParentWnd, dwStyle | CBRS_ALIGN_TOP, nID, enableSelection))
{
return FALSE;
}
//----------------------------
// Remove borders and gripper:
//----------------------------
SetBarStyle (
GetBarStyle ()
& ~(CBRS_GRIPPER | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
CRect rectWnd = rect;
MoveWindow (rectWnd);
ContextToSize ();
SetOwner (pParentWnd);
SetCommandID (nID);
m_bIsCtrl = TRUE;
// All commands will be routed via this dialog, not via the parent frame:
SetRouteCommandsViaFrame (FALSE);
return TRUE;
}
//*************************************************************************************
void CBCGPCalendarBar::Serialize (CArchive& ar)
{
CBCGPPopupMenuBar::Serialize (ar);
if (ar.IsLoading ())
{
ar >> m_bIsTearOff;
ar >> m_nCommandID;
Rebuild ();
AdjustLocations ();
}
else
{
ar << m_bIsTearOff;
ar << m_nCommandID;
}
}
//*************************************************************************************
void CBCGPCalendarBar::ShowCommandMessageString (UINT /*uiCmdId*/)
{
GetOwner()->SendMessage (WM_SETMESSAGESTRING,
m_nCommandID == (UINT) -1 ? AFX_IDS_IDLEMESSAGE : (WPARAM) m_nCommandID);
}
//*************************************************************************************
void CBCGPCalendarBar::SetDate (const COleDateTime& date)
{
int iOldYear = m_dateSelected.GetYear();
int iOldMonth = m_dateSelected.GetMonth();
m_dateSelected = date;
if (GetSafeHwnd () == NULL)
{
return;
}
COleDateTime firstDate = date;
m_LastAddedDate = date;
firstDate -= COleDateTimeSpan(firstDate.GetDay () - 1, 0, 0, 0);
int iYear = m_dateSelected.GetYear();
int iMonth = m_dateSelected.GetMonth();
CRect capRect;
GetClientRect (capRect);
capRect.bottom = capRect.top + m_iTitleHeight;
InvalidateRect (capRect);
int dDelta = (firstDate.GetDayOfWeek () - m_nWeekStart + 7) % 7;
firstDate -= COleDateTimeSpan(dDelta, 0, 0, 0);
COleDateTime weekDay = firstDate;
weekDay += COleDateTimeSpan(7, 0, 0, 0);
COleDateTime weekNo = firstDate;
weekNo += COleDateTimeSpan(6, 0, 0, 0);
m_iHighlighted = -1;
int iButton = 0;
int iNavBtn = 0;
COleDateTimeSpan oneDay(1,0,0,0);
for (POSITION pos = m_Buttons.GetHeadPosition (); pos != NULL; iButton++)
{
CRect rectButton;
CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) m_Buttons.GetNext (pos);
if (pButton->m_nStyle & TBBS_SEPARATOR)
{
continue;
}
COleDateTime dateToSet;
if (pButton->IsKindOf (RUNTIME_CLASS (CCalendarMonthButton)))
{
CCalendarMonthButton* pmonBtn = DYNAMIC_DOWNCAST(CCalendarMonthButton, pButton);
pButton->m_strText = GetMonthName(date.GetMonth ());
CSize btnSize = pmonBtn->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, 2);
#ifndef DISABLE_MONTH_POPUP
if (!m_bIsTearOff || (m_styleFlags & CBCGPCalendarBar::CBR_NAVIGATION_BUTTONS) == 0)
{
pButton->m_nStyle |= TBBS_DISABLED;
}
else
{
pButton->m_nStyle &= ~TBBS_DISABLED;
}
#else
pButton->m_nStyle |= TBBS_DISABLED;
#endif
CRect invRect = pmonBtn->Rect();
pButton->SetRect (rectButton);
InvalidateRect (invRect);
InvalidateRect (rectButton);
continue;
}
if (pButton->IsKindOf (RUNTIME_CLASS (CCalendarWeekNumButton)))
{
dateToSet = weekNo;
weekNo += COleDateTimeSpan(7, 0, 0, 0);
if (!(m_styleFlags & CBR_MULTISELECTION)
|| !m_bIsTearOff
|| !(m_styleFlags & CBR_WEEKNUMBER))
pButton->m_nStyle |= TBBS_DISABLED;
else
pButton->m_nStyle &= ~TBBS_DISABLED;
}
else if (pButton->IsKindOf (RUNTIME_CLASS (CCalendarTodayButton)))
{
dateToSet = COleDateTime::GetCurrentTime();
pButton->m_nStyle &= ~TBBS_DISABLED;
}
else if (pButton->IsKindOf (RUNTIME_CLASS (CCalendarNavigateButton)))
{
iNavBtn ++;
int iToYear = iYear;
int iToMonth = iMonth;
switch(iNavBtn)
{
case 1:
{
iToYear --;
}
break;
case 2:
{
iToMonth --;
if (!iToMonth)
{
iToMonth = 12;
iToYear --;
}
}
break;
case 3:
{
iToMonth ++;
if (iToMonth > 12)
{
iToMonth = 1;
iToYear ++;
}
}
break;
case 4:
{
iToYear ++;
}
break;
}
dateToSet = COleDateTime(iToYear, iToMonth, 1, 0, 0, 0);
pButton->m_nStyle &= ~TBBS_DISABLED;
}
else if (pButton->IsKindOf (RUNTIME_CLASS (CCalendarWeekButton)))
{
dateToSet = weekDay;
weekDay += oneDay;
if (!(m_styleFlags & CBR_MULTISELECTION)
|| m_pParentBtn != NULL
|| !(m_styleFlags & CBR_WEEKDAYSEL))
pButton->m_nStyle |= TBBS_DISABLED;
else
pButton->m_nStyle &= ~TBBS_DISABLED;
}
else if (pButton->IsKindOf (RUNTIME_CLASS (CBCGPCalendarButton)))
{
dateToSet = firstDate;
firstDate += oneDay;
}
else
{
continue;
}
CBCGPCalendarButton* pCalendarButton = DYNAMIC_DOWNCAST (CBCGPCalendarButton, pButton);
if (pCalendarButton == NULL)
{
continue;
}
ASSERT_VALID (pCalendarButton);
pCalendarButton->SetDate (dateToSet);
if (pCalendarButton->m_bHighlight)
{
pCalendarButton->m_bHighlight = FALSE;
CRect r = pCalendarButton->Rect ();
r.InflateRect (2, 2);
InvalidateRect (r);
}
}
if (iOldMonth != m_dateSelected.GetMonth() ||
iOldYear != m_dateSelected.GetYear())
{
OnSelectionChanged ();
}
}
//***************************************************************************************
void CBCGPCalendarBar::OnMouseMove(UINT nFlags, CPoint point)
{
if (!IsCustomizeMode () || m_bInternal)
{
CBCGPToolBar::OnMouseMove(nFlags, point);
}
if (m_nHoldTimerID && GetCapture() == this)
{
int iHit = HitTest (point);
if (iHit == -1)
{
KillTimer(m_nHoldTimerID);
m_nHoldTimerID = 0;
}
}
}
//***************************************************************************************
void CBCGPCalendarBar::OnTimer(UINT nIDEvent)
{
if (nIDEvent != nHoldMouseTimerID)
return;
if (m_nElapseInterval > 100)
{
m_nHoldTimerID = SetTimer (nHoldMouseTimerID, m_nElapseInterval -= 50, NULL);
}
CBCGPToolbarButton* pBtnHit = GetButton (m_iButtonCapture);
CCalendarNavigateButton* pNavi = DYNAMIC_DOWNCAST (CCalendarNavigateButton, pBtnHit);
if (pNavi)
{
SetDate(pNavi ->m_Calendar);
}
}
//***************************************************************************************
void CBCGPCalendarBar::OnLButtonDown(UINT nFlags, CPoint point)
{
//TODO: chech that hit-point is over navigate btn, start timer if so and each timer tick set new navi date
// maybe it is necessary to call SetCapture
if (IsCustomizeMode () && !m_bInternal)
{
return;
}
int iHit = HitTest (point);
CBCGPToolBar::OnLButtonDown(nFlags, point);
SetFocus ();
CBCGPToolbarButton* pBtnHit = GetButton (iHit);
CCalendarNavigateButton* pNavi = DYNAMIC_DOWNCAST (CCalendarNavigateButton, pBtnHit);
if (pNavi)
{
m_iButtonCapture = iHit;
SetCapture ();
CRect rect;
GetButtonRect (m_iButtonCapture, rect);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -