void CXTPCalendarViewGroup::AdjustLayout2(CDC* pDC, const CRect& rcGroup) { CXTPCalendarTheme* pTheme = XTP_SAFE_GET2(GetViewDay_(), GetView_(), GetTheme(), NULL); ASSERT(pTheme); //XTP_SAFE_CALL4(pTheme, Get_mw_ViewPart(), GetDayPart(), GetGroupPart(), AdjustLayout(this, pDC, rcGroup)); m_Layout.m_rcGroup = rcGroup; int nCount = GetViewEventsCount(); for (int i = 0; i < nCount; i++) { CXTPCalendarViewEvent* pVEvent = GetViewEvent_(i); ASSERT(pVEvent); if (pVEvent) { pVEvent->AdjustLayout2(pDC, rcGroup, i); } } }
void CXTPCalendarController::OnEvent_DatePicker(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM /*lParam*/) { wParam; switch (Event) { case XTP_NC_DATEPICKERBEFOREGOMODAL: if (m_pDatePickerCtrl && m_pCalendarCtrl) { OnEvent_CalendarView(XTP_NC_CALENDARVIEWWASCHANGED, 0, 0); } break; case XTP_NC_DATEPICKERBUTTONCLICKED: DBG_TRACE_DP_NF(_T("OnEvent: DatePickerButtonClicked - ID = %u. {CalendarController}. \n"), wParam); break; case XTP_NC_DATEPICKERMONTHCHANGED: m_DayInfoCache.UpActivePriority(); break; case XTP_NC_DATEPICKERSELECTIONCHANGED: DBG_TRACE_DP_NF(_T("OnEvent: XTP_NC_DATEPICKERSELECTIONCHANGED. {CalendarController}. \n")); if (m_pDatePickerCtrl && m_pCalendarCtrl && m_pCalendarCtrl->GetActiveView()) { BOOL bFastMode = m_pCalendarCtrl->m_bSwitchToDayViewIfPickedSingleDay; BOOL bChanged = FALSE; COleDateTime dtFrom; COleDateTime dtTo; if (m_pDatePickerCtrl->GetSelRange(dtFrom, dtTo)) { int nFirstDayOfWeekIndex = m_pDatePickerCtrl->GetFirstDayOfWeek(); int nFirstDayOfWeek = dtFrom.GetDayOfWeek(); BOOL bWeekStart = (nFirstDayOfWeekIndex == nFirstDayOfWeek); CXTPCalendarControl::CUpdateContext updateContext(m_pCalendarCtrl); int nSelRangeDays = CXTPCalendarUtils::GetTotalDays(dtTo - dtFrom) + 1; // count selected days int nSelDays = 0; COleDateTimeSpan spDay(1, 0, 0, 0); for (COleDateTime dtDay = dtFrom; dtDay <= dtTo; dtDay += spDay) { if (m_pDatePickerCtrl->IsSelected(dtDay)) nSelDays++; } BOOL bDaysCont = (nSelRangeDays == nSelDays); //LOGIC TO SELECT VIEW TYPE << // Day view int eViewMode = XTP_SAFE_GET2(m_pCalendarCtrl, GetActiveView(), GetViewType(), xtpCalendarDayView); if (eViewMode == xtpCalendarTimeLineView) { CXTPCalendarTimeLineView* pView = (CXTPCalendarTimeLineView* ) m_pCalendarCtrl->GetActiveView(); if (pView) { pView->SetStartViewDate(dtFrom); if (nSelRangeDays == 1) pView->SetTimeScaleID(xtpTSPID_Day); else if (nSelRangeDays <= 5) pView->SetTimeScaleID(xtpTSPID_WorkWeek); else if (nSelRangeDays <= 7) pView->SetTimeScaleID(xtpTSPID_Week); else pView->SetTimeScaleID(xtpTSPID_Month); } return; } if (nSelRangeDays <= nXTPMaxDayViewDays || !bDaysCont || !bWeekStart && nSelRangeDays <= 8) { m_bAdjustingView = TRUE; // to save WorkWeek view mode //if (eViewMode != xtpCalendarWorkWeekView || nSelDays != 1) if (bFastMode && ((eViewMode != xtpCalendarWorkWeekView) && (eViewMode != xtpCalendarFullWeekView)) || nSelDays != 1) eViewMode = xtpCalendarDayView; if (eViewMode == xtpCalendarMonthView) { CXTPCalendarMonthView* pMonthView = DYNAMIC_DOWNCAST(CXTPCalendarMonthView, m_pCalendarCtrl->GetActiveView()); if (pMonthView) { pMonthView->SelectDay(dtFrom); CXTPCalendarControl::CViewChangedContext viewChanged(m_pCalendarCtrl, xtpCalendarViewChangedLock); COleDateTime dtBegin = dtFrom; // Calculate weeks count COleDateTime dtWeekFromBegin = pMonthView->GetGrid()->ShiftDateToCell_00(dtFrom); COleDateTime dtWeekToEnd = pMonthView->GetGrid()->ShiftDateToCell_00(dtTo); dtWeekToEnd += COleDateTimeSpan(7, 0, 0, 0); int nSelectedWeeksRange = CXTPCalendarUtils::GetTotalDays(dtWeekToEnd - dtWeekFromBegin); int nWeeks = nSelectedWeeksRange / 7; nWeeks = max(XTP_CALENDAR_MONTHVIEW_SHOW_WEEKS_MIN, nWeeks); nWeeks = min(XTP_CALENDAR_MONTHVIEW_SHOW_WEEKS_MAX, nWeeks); pMonthView->GetGrid()->SetBeginDate(dtBegin); pMonthView->GetGrid()->SetWeeksCount(nWeeks); m_pCalendarCtrl->Populate(); } } else if ((eViewMode == xtpCalendarWorkWeekView) || (eViewMode == xtpCalendarFullWeekView) || (eViewMode == xtpCalendarWeekView)) { CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, m_pCalendarCtrl->GetActiveView()); if (pDayView) { pDayView->UnselectAllEvents(); COleDateTime dtWWStart; m_pCalendarCtrl->GetWorkDayStartTime(dtWWStart); dtWWStart = CXTPCalendarUtils::UpdateDate(dtWWStart, dtFrom); pDayView->SetSelection(dtWWStart, dtWWStart + pDayView->GetCellDuration()); } else { CXTPCalendarWeekView* pWeekView = DYNAMIC_DOWNCAST(CXTPCalendarWeekView, m_pCalendarCtrl->GetActiveView()); if (pWeekView) { pWeekView->SelectDay(dtFrom); pWeekView->SetBeginDate(dtFrom); m_pCalendarCtrl->Populate(); } } } //*** switch calendar view m_pCalendarCtrl->SwitchActiveView((XTPCalendarViewType)eViewMode); //*** CXTPCalendarDayView* pDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, m_pCalendarCtrl->GetActiveView()); // DayView - set visible days if (pDayView && eViewMode == xtpCalendarDayView) { COleDateTime dtSelStart, dtSelEnd; BOOL bAllDay = FALSE; BOOL bSel = pDayView->GetSelection(&dtSelStart, &dtSelEnd, &bAllDay); if (bSel) { COleDateTimeSpan spSel = dtSelEnd - dtSelStart; COleDateTimeSpan spSelMin = pDayView->GetCellDuration(); if (spSel < spSelMin) bSel = FALSE; } if (!bSel) { m_pCalendarCtrl->GetWorkDayStartTime(dtSelStart); dtSelEnd = dtSelStart + pDayView->GetCellDuration(); bAllDay = FALSE; } dtSelStart = CXTPCalendarUtils::UpdateDate(dtSelStart, dtFrom); dtSelEnd = CXTPCalendarUtils::UpdateDate(dtSelEnd, dtFrom); pDayView->ShowDay(dtFrom); pDayView->SetSelection(dtSelStart, dtSelEnd, bAllDay); // add other selected days to calendar view for (COleDateTime dtDay(dtFrom + spDay); dtDay <= dtTo; dtDay += spDay) { if (m_pDatePickerCtrl->IsSelected(dtDay)) pDayView->AddDay(dtDay); // add it to Calendar View } m_pCalendarCtrl->Populate(); } m_bAdjustingView = FALSE; bChanged = TRUE; } // Week view else if (nSelRangeDays == 7 && bDaysCont) { COleDateTime dtBegin = dtFrom; m_bAdjustingView = TRUE; if (m_pCalendarCtrl->m_bMultiColumnWeekMode) m_pCalendarCtrl->SwitchActiveView(xtpCalendarFullWeekView); else m_pCalendarCtrl->SwitchActiveView(xtpCalendarWeekView); CXTPCalendarWeekView* pWeekView = DYNAMIC_DOWNCAST(CXTPCalendarWeekView, m_pCalendarCtrl->GetActiveView()); if (pWeekView) { pWeekView->SetBeginDate(dtBegin); m_pCalendarCtrl->Populate(); } else if (m_pCalendarCtrl->m_bMultiColumnWeekMode) { CXTPCalendarDayView* pWeekDayView = DYNAMIC_DOWNCAST(CXTPCalendarDayView, m_pCalendarCtrl->GetActiveView()); if (pWeekDayView) { pWeekDayView->ShowDays(dtBegin, dtTo); m_pCalendarCtrl->Populate(); } } m_bAdjustingView = FALSE; bChanged = TRUE; } // Month view else { ASSERT(nSelRangeDays == nSelDays && nSelRangeDays > 7); m_bAdjustingView = TRUE; m_pCalendarCtrl->SwitchActiveView(xtpCalendarMonthView); CXTPCalendarMonthView* pMonthView = DYNAMIC_DOWNCAST(CXTPCalendarMonthView, m_pCalendarCtrl->GetActiveView()); if (pMonthView) { CXTPCalendarControl::CViewChangedContext viewChanged(m_pCalendarCtrl, xtpCalendarViewChangedLock); COleDateTime dtBegin = dtFrom; // Calculate weeks count COleDateTime dtWeekFromBegin = pMonthView->GetGrid()->ShiftDateToCell_00(dtFrom); COleDateTime dtWeekToEnd = pMonthView->GetGrid()->ShiftDateToCell_00(dtTo); dtWeekToEnd += COleDateTimeSpan(7, 0, 0, 0); int nSelectedWeeksRange = CXTPCalendarUtils::GetTotalDays(dtWeekToEnd - dtWeekFromBegin); int nWeeks = nSelectedWeeksRange / 7; nWeeks = max(XTP_CALENDAR_MONTHVIEW_SHOW_WEEKS_MIN, nWeeks); nWeeks = min(XTP_CALENDAR_MONTHVIEW_SHOW_WEEKS_MAX, nWeeks); pMonthView->GetGrid()->SetBeginDate(dtBegin); pMonthView->GetGrid()->SetWeeksCount(nWeeks); m_pCalendarCtrl->Populate(); } m_bAdjustingView = FALSE; bChanged = TRUE; } //LOGIC TO SELECT VIEW TYPE << if (bChanged) { OnEvent_CalendarView(XTP_NC_CALENDARVIEWWASCHANGED, 0, XTP_CC_DONT_SCROLL_DP); if (m_pDatePickerCtrl->IsModal()) { m_pCalendarCtrl->Invalidate(FALSE); m_pCalendarCtrl->RedrawControl(); } } } } break; default: ASSERT(FALSE); } }