BOOL CXTPCalendarRemindersManager::_Dismiss(CXTPCalendarReminder* pReminder)
{
	CXTPCalendarEventPtr ptrEvent = pReminder ? pReminder->GetEvent() : NULL;

	if (!pReminder || !ptrEvent)
	{
		ASSERT(FALSE);
		return FALSE;
	}

	CXTPAutoResetValue<BOOL> autoReset(m_bSkipOnEventChanged, FALSE);
	m_bSkipOnEventChanged = TRUE;

	if (ptrEvent->GetRecurrenceState() == xtpCalendarRecurrenceOccurrence)
	{
		CXTPCalendarRecurrencePatternPtr ptrPattern = ptrEvent->GetRecurrencePattern();
		CXTPCalendarEventPtr ptrMaster = ptrPattern ? ptrPattern->GetMasterEvent() : NULL;
		if (ptrMaster)
		{
			ptrPattern->SetOccReminder(ptrEvent, FALSE);

			VERIFY( ptrMaster->UpdateRecurrence(ptrPattern) );
			VERIFY( XTP_SAFE_GET1(ptrMaster->GetDataProvider(), ChangeEvent(ptrMaster), FALSE) );
		}
	}
	else
	{
		ptrEvent->SetReminder(FALSE);
		//ptrEvent->GetCustomProperties()->RemoveProperty(cszEventCustProp_NextReminderTime_Snoozed);

		VERIFY( XTP_SAFE_GET1(ptrEvent->GetDataProvider(), ChangeEvent(ptrEvent), FALSE) );
	}

	return TRUE;
}
BOOL CXTPCalendarRemindersManager::_RemoveSnoozeData(CXTPCalendarReminder* pRmd)
{
	CXTPCalendarEventPtr ptrEvent = pRmd->GetEvent();
	if (ptrEvent && ptrEvent->GetCustomProperties())
	{
		COleVariant varTmp;

		BOOL bSnoozed = ptrEvent->GetCustomProperties()->GetProperty(
							cszEventCustProp_NextReminderTime_Snoozed, varTmp);
		if (bSnoozed)
		{
			if (ptrEvent->GetRecurrenceState() == xtpCalendarRecurrenceOccurrence)
			{
				CXTPCalendarRecurrencePatternPtr ptrPattern = ptrEvent->GetRecurrencePattern();
				CXTPCalendarEventPtr ptrMaster = ptrPattern ? ptrPattern->GetMasterEvent() : NULL;
				if (ptrMaster)
				{
					ptrPattern->SetOccReminder(ptrEvent, xtpCalendarRmdPrm_Default, (DATE)xtpCalendarRmdPrm_Default);

					VERIFY( ptrMaster->UpdateRecurrence(ptrPattern) );
					VERIFY( XTP_SAFE_GET1(ptrMaster->GetDataProvider(), ChangeEvent(ptrMaster), FALSE) );
				}
			}
			else
			{
				ptrEvent->GetCustomProperties()->RemoveProperty(cszEventCustProp_NextReminderTime_Snoozed);
				VERIFY( XTP_SAFE_GET1(ptrEvent->GetDataProvider(), ChangeEvent(ptrEvent), FALSE) );
			}

			return TRUE;
		}
	}
	return FALSE;
}
int CXTPCalendarDayViewTimeScale::CalcWidth(CDC* pDC)
{
	// calculate actual correct width
	int nWidth1 = m_nWidth, nWidth2 = m_nWidth;

	// calculate width for midnight
	COleDateTime dtMid(0, 0);
	CString strHour, strMin;
	Format(dtMid, TRUE, &strHour, &strMin);

	COleDateTimeSpan spScaleInterval = GetScaleInterval();
	int nRowHeight = XTP_SAFE_GET1(m_pDayView, GetRowHeight(), 1);
	int nHourHeight = nRowHeight * (CXTPCalendarUtils::GetTotalMinutes(spScaleInterval) < 60 ? 2 : 1);

	XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleCellPart(),
		CalcWidth(pDC, strHour, strMin, nHourHeight, nWidth1));

	// calculate width for midday
	dtMid += COleDateTimeSpan(0, 12, 0, 0);
	Format(dtMid, TRUE, &strHour, &strMin);

	XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleCellPart(),
		CalcWidth(pDC, strHour, strMin, nHourHeight, nWidth2));

	// choose the widest one
	m_nWidth = max(nWidth1, nWidth2);

	return m_nWidth;
}
Пример #4
0
CXTPCalendarControl* CXTPCalendarViewDay::GetCalendarControl() const
{
	ASSERT(this);
	if (!this)
	{
		return NULL;
	}
	return XTP_SAFE_GET1(GetView_(), GetCalendarControl(), NULL);
}
Пример #5
0
UINT CXTPCalendarViewGroup::GetScheduleID()
{
	UINT uScheduleID = XTP_CALENDAR_UNKNOWN_SCHEDULE_ID;
	if (XTP_SAFE_GET1(GetResources(), GetCount(), 0) &&
		XTP_SAFE_GET3(GetResources(), GetAt(0), GetSchedules(), GetSize(), 0) )
	{
		uScheduleID = XTP_SAFE_GET3(GetResources(), GetAt(0), GetSchedules(),
									GetAt(0), 0);
	}

	return uScheduleID;
}
CRect CXTPCalendarWeekViewDay::GetDayEventsRect() const
{
	int nColHeaderHeight = XTP_SAFE_GET1(GetView(), GetRowHeight(), 0);
	CRect rcDayEvents = m_Layout.m_rcDay;
	//rcDayEvents.bottom -= min(2, rcDayEvents.Height());
	rcDayEvents.top += min(nColHeaderHeight + 0, rcDayEvents.Height());
	int nBotSpace = XTP_SAFE_GET5(GetView(), GetCalendarControl(), GetTheme(),
		GetWeekViewPart(), GetDayPart(), GetExpandButtonHeight(), 0);

	rcDayEvents.bottom -= min(nBotSpace + 2, rcDayEvents.Height());


	return rcDayEvents;
}
Пример #7
0
BOOL CXTPCalendarViewDay::IsSelected() const
{
	return XTP_SAFE_GET1(GetView_(), SelectionContains(GetDayDate()), FALSE);
}
Пример #8
0
UINT CXTPCalendarViewDay::SetTimer(UINT uTimeOut_ms)
{
	return XTP_SAFE_GET1(GetView_(), SetTimer(uTimeOut_ms), 0);
}
BOOL CXTPCalendarRemindersManager::Snooze(CXTPCalendarReminder* pReminder,
		int nMinutesAfterNow)
{
	const int cnMaxSnoozeMinutes = (60*24*365) * 1000; // 1000 years

	// WARNING. no sense to snooze before now.
	ASSERT(nMinutesAfterNow >= 1);

	// WARNING. do you really need to snooze so far.
	ASSERT(nMinutesAfterNow <= cnMaxSnoozeMinutes);

	nMinutesAfterNow = max(1, min(nMinutesAfterNow, cnMaxSnoozeMinutes));

	CXTPCalendarEventPtr ptrEvent = pReminder ? pReminder->GetEvent() : NULL;

	if (!pReminder || !ptrEvent)
	{
		ASSERT(FALSE);
		return FALSE;
	}

	pReminder->m_dtNextReminderTime = CXTPCalendarUtils::GetCurrentTime();
	pReminder->m_dtNextReminderTime += CXTPCalendarUtils::Minutes2Span(nMinutesAfterNow);

	m_arWaitingReminders.Add(pReminder, TRUE);

	int nIdx = m_arActiveReminders.Find(pReminder);
	if (nIdx >= 0)
	{
		m_arActiveReminders.RemoveAt(nIdx);
	}

	CXTPAutoResetValue<BOOL> autoReset(m_bSkipOnEventChanged, FALSE);
	m_bSkipOnEventChanged = TRUE;

	if (ptrEvent->GetRecurrenceState() == xtpCalendarRecurrenceOccurrence)
	{
		CXTPCalendarRecurrencePatternPtr ptrPattern = ptrEvent->GetRecurrencePattern();
		CXTPCalendarEventPtr ptrMaster = ptrPattern ? ptrPattern->GetMasterEvent() : NULL;
		if (ptrMaster)
		{
			ptrPattern->SetOccReminder(ptrEvent, xtpCalendarRmdPrm_DontChange,
										(DATE)pReminder->m_dtNextReminderTime);

			VERIFY( ptrMaster->UpdateRecurrence(ptrPattern) );
			VERIFY( XTP_SAFE_GET1(ptrMaster->GetDataProvider(), ChangeEvent(ptrMaster), FALSE) );
		}
	}
	else
	{
		VERIFY( ptrEvent->GetCustomProperties()->SetProperty(
				cszEventCustProp_NextReminderTime_Snoozed,
				(DATE)pReminder->m_dtNextReminderTime) );

		VERIFY( XTP_SAFE_GET1(ptrEvent->GetDataProvider(), ChangeEvent(ptrEvent), FALSE) );
	}

	NotifyReminders(xtpCalendarReminderSnoozed, (LPARAM)pReminder);

	return TRUE;
}
void CXTPCalendarController::CXTPDayInfoCache::OnRefreshDays(int nDaysCountToRefresh)
{
    ASSERT(m_pOwner);

    if (!XTP_SAFE_GET1(m_pOwner, m_pResourcesNf, NULL))
    {
        if (!m_dwWaitingDataTime)
        {
            m_dwWaitingDataTime = GetTickCount();
            DBG_TRACE_DP_TIMER(_T("XTPCalendarController::DayInfoCache - OnRefreshDays, Start Wait for data\n"));
        }

        if (abs((long)(GetTickCount() - m_dwWaitingDataTime)) >= 5000)
        {
            m_dwWaitingDataTime = 0;

            if (m_uTimerID)
            {
                DBG_TRACE_DP_TIMER(_T("XTPCalendarController::DayInfoCache - OnRefreshDays, KillTimer (ID = %d) \n"), m_uTimerID);
                DBG_TRACE_DP_TIMER(_T("XTPCalendarController::DayInfoCache - OnRefreshDays, end Wait for data\n"));

                KillTimer();

                OnSelfClearOld();
            }
        }
        return;
    }
    else
    {
        if (m_dwWaitingDataTime)
        {
            DBG_TRACE_DP_TIMER(_T("XTPCalendarController::DayInfoCache - OnRefreshDays, end Wait for data\n"));
        }
        m_dwWaitingDataTime = 0;
    }

    //***************************************************
    for (int i = 0; i < nDaysCountToRefresh; i++)
    {
        long nDay_min = LONG_MAX;
        UINT uPriority_max = 0;

        POSITION pos = m_mapDaysToRefresh.GetStartPosition();
        while (pos)
        {
            long nDay = 0;
            UINT uPriority = 0;
            m_mapDaysToRefresh.GetNextAssoc(pos, nDay, uPriority);

            if (uPriority == uPriority_max && nDay < nDay_min ||
                    uPriority > uPriority_max)
            {
                uPriority_max = uPriority;
                nDay_min = nDay;
            }
        }

        if (nDay_min < LONG_MAX)
        {
            m_mapDaysToRefresh.RemoveKey(nDay_min);

            COleDateTime dtDay((DATE)nDay_min);
            BOOL bHasEvents = XTP_SAFE_GET1(m_pOwner, _HasEvents(dtDay), FALSE);

            UpdateDayInfo(dtDay, bHasEvents);
        }
    }
    //***************************************************

    if (m_mapDaysToRefresh.GetCount() == 0 && m_uTimerID)
    {
        DBG_TRACE_DP_TIMER(_T("XTPCalendarController::DayInfoCache - OnRefreshDays, KillTimer (ID = %d) \n"), m_uTimerID);
        DBG_TRACE_DP_TIMER(_T("XTPCalendarController::DayInfoCache - Days In Cache %d \n"), m_mapDaysInfo.GetCount());

        KillTimer();

        OnSelfClearOld();
    }

    if (abs((long)(GetTickCount() - m_dwLastRedrawTime)) >= 500 || m_uTimerID == 0)
    {
        XTP_SAFE_CALL2(m_pOwner, m_pDatePickerCtrl, RedrawControl());
        m_dwLastRedrawTime = GetTickCount();
    }
}
void CXTPCalendarDayViewTimeScale::Draw(CDC* pDC)
{
	ASSERT(pDC && m_pDayView);

	if (!pDC || !m_pDayView)
	{
		return;
	}

	pDC->FillSolidRect(m_Layout.m_rcHeader, GetSysColor(COLOR_3DFACE));
	pDC->SetBkMode(TRANSPARENT);

	int nRowHeight = XTP_SAFE_GET1(m_pDayView, GetRowHeight(), 0);

	if (nRowHeight <= 0)
		return;

	const int nRowCount = m_pDayView->GetVisibleRowCount();
	const int nTopRow = m_pDayView->GetTopRow();
	COleDateTimeSpan spScaleInterval = GetScaleInterval();

	if (CXTPCalendarUtils::GetTotalMinutes(spScaleInterval) < 1)
	{
		ASSERT(FALSE);
		spScaleInterval.SetDateTimeSpan(0, 0, 5, 0);
	}

	//=== Calculate 'now' line. Draw it's BK ================================
	int nNowLineY = 0;
	if (m_bDrawNowLineDyn)
	{
		int nBottomRow = nTopRow + m_pDayView->GetVisibleRowCount();
		COleDateTime dtTopTime = m_pDayView->GetCellTime(nTopRow);
		COleDateTime dtBottomTime = m_pDayView->GetCellTime(nBottomRow);
		COleDateTimeSpan spView = dtBottomTime - dtTopTime;

		COleDateTime dtNow = CXTPCalendarUtils::GetCurrentTime();
		dtNow = CXTPCalendarUtils::ResetDate(dtNow);

		COleDateTimeSpan spNow = dtNow - dtTopTime;

		double dPixelPerSecond = m_Layout.m_rcTimeZone.Height() / (double)CXTPCalendarUtils::GetTotalSeconds(spView);

		int nDlta = int(CXTPCalendarUtils::GetTotalSeconds(spNow) * dPixelPerSecond);
		nNowLineY = m_Layout.m_rcTimeZone.top + nDlta;

		XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleHeaderPart(),
			DrawNowLine(pDC, m_pDayView, m_Layout.m_rcTimeZone, nNowLineY, TRUE) );
	}

	//================================================================
	int nTimeShiftCorrectorY = 0;
	COleDateTimeSpan spShiftCorrector(0);
	int nScaleInterval_min = max(1, (int)CXTPCalendarUtils::GetTotalMinutes(spScaleInterval));
	double dPixelPerMin = (double)nRowHeight / (double)nScaleInterval_min;

	if (CXTPCalendarUtils::GetTotalHours(spScaleInterval) < 1)
	{
		int nMul = m_nTimeshift_min / 60;
		int nMod = m_nTimeshift_min % 60;
		int nShiftCorrector_min = (nMul + (nMod ? 1 :0))*60 - m_nTimeshift_min;

		//-------------------------------------------------------------------
		int nMul2 = nShiftCorrector_min / nScaleInterval_min;
		int nMod2 = nShiftCorrector_min % nScaleInterval_min;
		int nShiftCorrector2_min = (nMul2 + (nMod2 ? 1 :0)) * nScaleInterval_min;

		nTimeShiftCorrectorY = (int)(dPixelPerMin * nShiftCorrector2_min);

		spShiftCorrector = CXTPCalendarUtils::Minutes2Span(nShiftCorrector_min);
	}

	// draw time scale header
	COleDateTimeSpan spShift = CXTPCalendarUtils::Minutes2Span(m_nTimeshift_min);

	// draw time scale rows
	if (CXTPCalendarUtils::GetTotalHours(spScaleInterval) >= 1)
	{
		// draw time scale cells one by one
		for (int i = 0; i < nRowCount; i++)
		{
			CRect rcCell(m_Layout.m_rcTimeZone.left,
						m_Layout.m_rcTimeZone.top + nRowHeight * i,
						m_Layout.m_rcTimeZone.right,
						m_Layout.m_rcTimeZone.top + nRowHeight * (i + 1));

			COleDateTime dtTime = m_pDayView->GetCellTime(nTopRow + i);

			dtTime += spShift;
			CString str = Format(dtTime, FALSE);

			XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleCellPart(),
							DrawHourCell(pDC, rcCell, str, FALSE));
		}
	}
	else
	{
		COleDateTimeSpan spHour(0, 1, 0, 0);

		spShift += spShiftCorrector;

		int nRowPerHour = (int)((double)spHour / (double)spScaleInterval + XTP_HALF_SECOND);
		ASSERT(nRowPerHour > 0);
		nRowPerHour = max(1, nRowPerHour);
		const int nHourCellHeight = nRowHeight*nRowPerHour;

		// Adjust time font size
		CRect rcStartCell(m_Layout.m_rcTimeZone);

		rcStartCell.top += nTimeShiftCorrectorY;

		rcStartCell.bottom = rcStartCell.top + nHourCellHeight;

		//XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleCellPart(),
		//              AdjustTimeFont(pDC, rcStartCell));

		//-------------------------------------------------------------------
		int nHrCellDiv = m_Layout.m_rcTimeZone.Height() / rcStartCell.Height();
		int nHrCellMod = m_Layout.m_rcTimeZone.Height() / rcStartCell.Height();

		int nDrawCellCount = nHrCellDiv + (nHrCellMod ? 1 :0);

		COleDateTime dtStartCell = m_pDayView->GetCellTime(nTopRow);
		dtStartCell += spShift;
		int nSCMinute = dtStartCell.GetMinute();
		if (nSCMinute != 0)
		{
			int nMinutesShiftY = (int)(dPixelPerMin * nSCMinute);
			rcStartCell.top -= nMinutesShiftY;
			rcStartCell.bottom -= nMinutesShiftY;

			dtStartCell.SetTime(dtStartCell.GetHour(), 0, 0);

			nDrawCellCount++;
		}

		//while (rcStartCell.top > m_rcTimeZone.top)
		for (int n = 0; rcStartCell.top > m_Layout.m_rcTimeZone.top && n < 100; n++)
		{
			dtStartCell -= spHour;

			rcStartCell.top -= nHourCellHeight;
			rcStartCell.bottom -= nHourCellHeight;

			nDrawCellCount++;
		}

		// draw time scale cells with only one big hour number
		BOOL bTopCell = TRUE;
		CRect rcCell = rcStartCell;
		for (int i = 0; i < nDrawCellCount; i++)
		{
			COleDateTime dtCell = dtStartCell + COleDateTimeSpan(i * (double)spHour);
			ASSERT(dtCell.GetMinute() == 0);

			CString strHour, strMin;
			Format(dtCell, bTopCell, &strHour, &strMin);

			if (rcCell.top >= m_Layout.m_rcTimeZone.top)
			{
				bTopCell = FALSE;
			}

			// draw text
			XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleCellPart(),
							DrawBigHourCell(pDC, rcCell, strHour, strMin, nRowPerHour, FALSE));

			rcCell.top += nHourCellHeight;
			rcCell.bottom += nHourCellHeight;
		}
	}

	//*** draw 'now' line
	if (m_bDrawNowLineDyn)
	{
		XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleHeaderPart(),
			DrawNowLine(pDC, m_pDayView, m_Layout.m_rcTimeZone, nNowLineY, FALSE) );
	}

	//*** Draw Expand Signs
	XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleHeaderPart(),
			DrawExpandSigns(pDC, m_pDayView, m_Layout.m_rcTimeZone) );

	//*** Draw header
	CRect rcHeader(m_Layout.m_rcHeader.left, m_Layout.m_rcHeader.top, m_Layout.m_rcHeader.right, m_Layout.m_rcTimeZone.top);

	XTP_SAFE_CALL3(m_pDayView, GetPaintManager(), GetDayViewTimeScaleHeaderPart(),
					OnDraw(pDC, m_pDayView, rcHeader, m_strCaption));
}
COleDateTimeSpan CXTPCalendarDayViewTimeScale::GetScaleInterval() const
{
	return XTP_SAFE_GET1(m_pDayView, GetScaleInterval(), COleDateTimeSpan(0, 0, 1, 0));
}