📄 dateweek.c
字号:
* FUNCTION: WeekViewInitDays
*
* DESCRIPTION: Check the data of the days in the current week and
* extend the week's time range if nesc. Assumes the
* week has already been initialized.
*
* This routine is performing all of the heavy data access
* work, so that the screen can be drawn quickly without
* the burden of the database.
*
* PARAMETERS: FormPtr frm - The currently active (WeekView) form
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* kcr 11/13/95 Initial Revision
*
***********************************************************************/
static void WeekViewInitDays (FormPtr frm)
{
int i;
RectangleType dayBounds;
Int16 dayWidth;
WeekType *week;
UInt16 counts[daysInWeek];
MemHandle apptLists[daysInWeek];
ErrFatalDisplayIf(!WeekObjectH, "Unallocated Week View object");
week = MemHandleLock (WeekObjectH);
// Initialize the days:
dayWidth = (week->bounds.extent.x - weekViewTimeDisplayWidth) / daysInWeek;
dayBounds.topLeft.x = week->bounds.topLeft.x + weekViewTimeDisplayWidth;
dayBounds.topLeft.y = week->bounds.topLeft.y;
dayBounds.extent.x = dayWidth;
dayBounds.extent.y = week->hourHeight * weekViewNumDispHours +
weekViewDayDisplayHeight +
weekViewDateDisplayHeight;
// Get all the appointments in the week.
ApptGetAppointments (ApptDB, week->startDate, daysInWeek,
apptLists, counts);
for (i = 0; i < daysInWeek; i++)
{
WeekViewDayInit(&(week->days[i]),
(i + StartDayOfWeek) % daysInWeek,
&dayBounds,
&(week->firstEventHour),
&(week->lastEventHour),
apptLists[i], counts[i]);
dayBounds.topLeft.x += dayWidth; // Next day bounds
}
// Initailize scroll controls
WeekViewUpdateScrollers(frm);
MemPtrUnlock (week);
} // end of WeekViewInitDays
/***********************************************************************
*
* FUNCTION: WeekViewSetTitle
*
* DESCRIPTION: This routine set the title of the Week View form
*
* PARAMETERS: week - pointer to week object (WeekType)
*
* RETURNED: nothing
*
* HISTORY:
* 07/15/96 art Created by Art Lamb
* 03/11/97 scl added dfMYMedNoPost for French 2.0 ROM
* 07/07/99 kwk use soft constant for date format.
* 09/12/99 kwk Re-wrote to use templates for all dates.
* 10/05/99 kwk Let localizers control location of full date (w/year)
* in the "same year, spans months" layout.
* 10/7/99 EL fixed title computation for date dec 31 2031.
*
***********************************************************************/
static void WeekViewSetTitle (WeekType * week)
{
Char startDate[longDateStrLength];
Char endDate[longDateStrLength];
MemHandle templateH;
Char* templateP;
Char* title;
UInt16 startDateID, endDateID, templateID;
UInt16 weekLastDayIndex;
// Find the last valid day (out of range days are number outOfRangeDay)
weekLastDayIndex = daysInWeek - 1;
while (weekLastDayIndex > 0) {
if (week->days[weekLastDayIndex].date.day != outOfRangeDay)
break;
else
weekLastDayIndex--;
}
// Set the title of the form to be the localized month/year date of the
// StartDayOfWeek. The format shall be "Mmm 'YY - Mmm 'YY", or
// "Mmm - Mmm 'YY" if the year is the same, or "Mmm 'YY" if the month
// is the same.
if (week->startDate.year != week->days[weekLastDayIndex].date.year)
{
// Start/end year is different, so go for "Mmm 'YY - Mmm 'YY".
startDateID = WeekViewTitleFullDateStrID;
endDateID = WeekViewTitleFullDateStrID;
templateID = WeekViewTitleTwoDatesStrID;
}
else if ((week->startDate.month != week->days[weekLastDayIndex].date.month) &&
(week->days[weekLastDayIndex].date.day != outOfRangeDay))
{
// Start/end year is the same, but month is different, so use "Mmm - Mmm 'YY"
// or "Mmm 'YY - Mmm", depending on weekViewYearFirst soft constant.
if (ResLoadConstant(weekViewYearFirst) == false)
{
startDateID = WeekViewTitleShortDateStrID;
endDateID = WeekViewTitleFullDateStrID;
}
else
{
startDateID = WeekViewTitleFullDateStrID;
endDateID = WeekViewTitleShortDateStrID;
}
templateID = WeekViewTitleTwoDatesStrID;
}
else
{
// Start/end year & month are the same, so use "Mmm 'YY"
startDateID = WeekViewTitleFullDateStrID;
endDateID = WeekViewTitleEmptyDateStrID;
templateID = WeekViewTitleOneDateStrID;
}
templateH = DmGetResource(strRsc, startDateID);
templateP = (Char*)MemHandleLock(templateH);
DateTemplateToAscii(templateP, week->startDate.month, week->startDate.day,
week->startDate.year + firstYear, startDate, sizeof(startDate) - 1);
if (startDateID != endDateID)
{
MemPtrUnlock((MemPtr)templateP);
templateH = DmGetResource(strRsc, endDateID);
templateP = (Char*)MemHandleLock(templateH);
}
DateTemplateToAscii(templateP, week->days[weekLastDayIndex].date.month,
week->days[weekLastDayIndex].date.day, week->days[weekLastDayIndex].date.year + firstYear,
endDate, sizeof(endDate) - 1);
MemPtrUnlock((MemPtr)templateP);
templateH = DmGetResource(strRsc, templateID);
templateP = (Char*)MemHandleLock(templateH);
title = TxtParamString(templateP, startDate, endDate, NULL, NULL);
MemPtrUnlock((MemPtr)templateP);
FrmCopyTitle (FrmGetActiveForm (), title);
MemPtrFree((MemPtr)title);
TimeDisplayed = false;
AttnIndicatorEnable(true);
}
/***********************************************************************
*
* FUNCTION: WeekViewInit
*
* DESCRIPTION: This routine initializes the structures used for the
* WeekView. The start date will be set and the start
* and end of the display range will be set.
*
* PARAMETERS: FormPtr frm - The currently active (WeekView) form
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* kcr 7/27/95 Initial Revision
* kcr 10/4/95 New title date format
* kcr 10/9/95 Make sure lastEventHour does not get adjusted past
* midnight. Bug #260.
* kcr 10/12/95 handle beginning of date range & end of date
* range.
* kwk 07/07/99 Create date range title in localizable manner.
* 2002-10-21 CS If we've got support for the lunar calendar, then
* display the lunar view push button (otherwise spread
* buttons out a bit).
*
***********************************************************************/
static void WeekViewInit (FormPtr frm)
{
int i, skipFirstDays = 0, skipLastDays = 0;
DateType tempDate;
WeekType *week;
UInt16 index;
UInt16 startDay;
UInt16 weekNumber;
Char weekNumStr[16];
Char *templateP;
Char *weekString;
// Allocate currWeek object & day objects
WeekObjectH = MemHandleNew (sizeof (WeekType));
ErrFatalDisplayIf(!WeekObjectH, "Allocation error");
week = MemHandleLock (WeekObjectH);
// Set bounds of WeekView
index = FrmGetObjectIndex (frm, WeekDayDisplay);
FrmGetObjectBounds (frm, index, &(week->bounds));
week->bounds.extent.x -= weekHMargin;
// Determine the start date for this week based on the current 'Date' and
// the StartDayOfWeek
week->startDate.year = Date.year;
week->startDate.month = Date.month;
week->startDate.day = Date.day;
startDay = DayOfWeek (Date.month, Date.day, Date.year+firstYear);
// Current day of week
// Adjust startDate backwards to previous occurrance of StartDayOfWeek
if (startDay > StartDayOfWeek)
DateAdjust (&(week->startDate), - ((Int32) (startDay - StartDayOfWeek)));
else if (StartDayOfWeek > startDay)
DateAdjust (&(week->startDate),
- ((Int32)(startDay + daysInWeek - StartDayOfWeek)));
// Make sure we have not run into the start of the legal date
// range. If this has happened, we will skip the
// dates betweeen the StartDayOfWeek and the beginning of the legal
// date range.
if ((week->startDate.year == 0) &&
(week->startDate.month == 1) &&
(week->startDate.day == 1))
{
startDay = DayOfWeek (1, 1, firstYear);
if (startDay > StartDayOfWeek)
skipFirstDays = startDay - StartDayOfWeek;
else if (StartDayOfWeek > startDay)
skipFirstDays = daysInWeek + startDay - StartDayOfWeek;
}
// Make sure we have not run into the end of the legal date
// range. If this happens, we will skip the days between the
// end of the date range and the week->startDate+daysInWeek.
else if ((week->startDate.year == numberOfYears - 1) &&
(week->startDate.month == 12) &&
(week->startDate.day > (31 - (daysInWeek - 1))))
{
startDay = DayOfWeek (1, 1, lastYear);
if (startDay >= StartDayOfWeek)
skipLastDays = daysInWeek - (startDay - StartDayOfWeek) - 1;
else
skipLastDays = daysInWeek - (startDay + daysInWeek - StartDayOfWeek)
- 1;
}
// week->startDate is now the date of the first instance of
// StartDayOfWeek <= the current Date. An exception occurs when
// the beginning of the legal date range has been hit. In this case,
// week->startDate falls on StartDayOfWeek+skipFirstDays.
// Determine the scrolling range, and the initial displayed time range:
//
// These vars hold the elligible scrolling range for the current week.
// The range will be expanded as necessary as the days' events are
// examined.
week->firstEventHour = DayStartHour;
week->lastEventHour = DayEndHour;
// If range is still less than a screenful, stretch it. End of display
// may not extend past midnight, however.
if ((week->lastEventHour - week->firstEventHour < weekViewNumDispHours) &&
(week->firstEventHour + weekViewNumDispHours > 24))
{ // Have to stretch range at both ends
week->lastEventHour = 24;
week->firstEventHour = week->lastEventHour - weekViewNumDispHours;
}
else if (week->lastEventHour - week->firstEventHour < weekViewNumDispHours)
week->lastEventHour = week->firstEventHour + weekViewNumDispHours;
week->hourHeight = (week->bounds.extent.y -
weekViewDayDisplayHeight -
weekViewDateDisplayHeight) / weekViewNumDispHours;
// The display will initially show all events from the start of the
// user's day range to the end of the vertical screen space. If there
// is room for more hours of data than the user's day range specified,
// a full screenful will be shown anyway.
week->startHour = week->firstEventHour;
week->endHour = week->firstEventHour + weekViewNumDispHours;
// Set the dates of each day so they can be drawn before initializing the
// days.
tempDate = week->startDate;
for (i = 0; i < daysInWeek; i++)
{
if ((i < skipFirstDays) ||
(i >= (daysInWeek - skipLastDays)))
{
week->days[i].date.day = outOfRangeDay;
}
else
{
week->days[i].date = tempDate;
DateAdjust (&tempDate, 1); // Next date
}
}
// Set the title of the form
WeekViewSetTitle (week);
// Create the week number string. We'll load the template string
// and then substitute in the number string.
weekNumber = GetWeekNumber (Date.month, Date.day, Date.year+firstYear);
StrIToA(weekNumStr, weekNumber);
if (StrLen(weekNumStr) == 1)
{
weekNumStr[1] = weekNumStr[0];
weekNumStr[0] = chrNumericSpace;
weekNumStr[2] = '\0';
}
templateP = (Char*)MemHandleLock(DmGetResource(strRsc, weekNumberTemplateStrID));
weekString = DateParamString(templateP, NULL, weekNumStr, NULL, NULL);
FrmCopyLabel(frm, WeekNumberLabel, weekString);
MemPtrFree(weekString);
MemPtrUnlock(templateP);
// Display the Lunar View push button if we've got support for it.
if (DateSupportsLunarCalendar()) {
FrmShowObject (frm, FrmGetObjectIndex(frm, WeekLunarViewButton));
// Otherwise, spread the buttons out a bit to make use of extra space.
} else {
RectangleType lastButtonBounds;
RectangleType buttonBounds;
FrmGetObjectBounds( frm,
FrmGetObjectIndex(frm, WeekMonthViewButton),
&lastButtonBounds);
FrmGetObjectBounds( frm,
FrmGetObjectIndex(frm, WeekAgendaViewButton),
&buttonBounds);
buttonBounds.topLeft.x = ( lastButtonBounds.topLeft.x
+ lastButtonBounds.extent.x
+ 1);
FrmSetObjectBounds( frm,
FrmGetObjectIndex(frm, WeekAgendaViewButton),
&buttonBounds);
lastButtonBounds = buttonBounds;
FrmGetObjectBounds( frm,
FrmGetObjectIndex(frm, WeekGoToButton),
&buttonBounds);
buttonBounds.topLeft.x = ( lastButtonBounds.topLeft.x
+ lastButtonBounds.extent.x
+ kButtonSpacing);
FrmSetObjectBounds( frm,
FrmGetObjectIndex(frm, WeekGoToButton),
&buttonBounds);
}
// Highlight the Week View push button.
FrmSetControlGroupSelection (frm, DayViewGroup, WeekWeekViewButton);
week->behindDesc = NULL;
MemPtrUnlock (week);
} // end of WeekViewInit
/***********************************************************************
*
* FUNCTION: WeekViewFree
*
* DESCRIPTION: This routine is called when the WeekView is being torn
* winDown. It's primary function is to free allocated
* memory.
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* kcr 8/9/95 Initial Revision
*
***********************************************************************/
static void WeekViewFree (void)
{
int i;
WeekType
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -