📄 dateday.c
字号:
SysStringByIndex(freqOrdinal2ndStrlID, index, otherFreqName, sizeof(otherFreqName));
descP = SubstituteStr (descP, frequenceToken, otherFreqName, StrLen(otherFreqName));
}
else
{
resH = DmGetResource (strRsc, freqOrdinalsStrID);
resP = MemHandleLock (resH);
for (i = 1; i < freq; i++)
resP = StrChr (resP, spaceChr) + 1;
len = (UInt16) (StrChr (resP, spaceChr) - resP);
descP = SubstituteStr (descP, frequenceToken, resP, len);
MemHandleUnlock (resH);
}
// Substitute the repeat week string (1st, 2nd, 3rd, 4th, or last)
// for the week ordinal token.
if (repeat.repeatType == repeatMonthlyByDay)
{
resH = DmGetResource (strRsc, weekOrdinalsStrID);
resP = MemHandleLock (resH);
for (i = 0; i < repeat.repeatOn / daysInWeek; i++)
resP = StrChr (resP, spaceChr) + 1;
len = (UInt16) (StrChr (resP, spaceChr) - resP);
descP = SubstituteStr (descP, weekOrdinalToken, resP, len);
MemHandleUnlock (resH);
}
else
{
// make sure the week ordinal token really doesn't appear
ErrNonFatalDisplayIf(StrStr(descP, weekOrdinalToken) != NULL, "week ordinal not substituted");
}
// Substitute the repeat date string (1st, 2nd, ..., 31th) for the
// day ordinal token.
resH = DmGetResource (strRsc, dayOrdinalsStrID);
resP = MemHandleLock (resH);
for (i = 1; i < details->when.date.day; i++)
resP = StrChr (resP, spaceChr) + 1;
len = (UInt16) (StrChr (resP, spaceChr) - resP);
descP = SubstituteStr (descP, dayOrdinalToken, resP, len);
MemHandleUnlock (resH);
// Draw the description.
MemHandleUnlock (descH);
FldFreeMemory (fld);
FldSetTextHandle (fld, descH);
FldDrawField (fld);
}
/***********************************************************************
*
* FUNCTION: RepeatSelectEndDate
*
* DESCRIPTION: This routine selects the end date of a repeating event.
*
* PARAMETERS: event - pointer to a popup select event
*
* RETURNED: nothing
*
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 7/16/95 Initial Revision
*
***********************************************************************/
static void RepeatSelectEndDate (EventType* event)
{
Int16 month, day, year;
Char* titleP;
MemHandle titleH;
DetailsPtr details;
// "No due date" items selected?
if (event->data.popSelect.selection == repeatNoEndDateItem)
{
DateToInt (RepeatEndDate) = apptNoEndDate;
}
// "Select date" item selected?
else if (event->data.popSelect.selection == repeatChooseDateItem)
{
details = RepeatDetailsP;
if ( DateToInt (RepeatEndDate) == apptNoEndDate)
{
year = details->when.date.year + firstYear;
month = details->when.date.month;
day = details->when.date.day;
}
else
{
year = RepeatEndDate.year + firstYear;
month = RepeatEndDate.month;
day = RepeatEndDate.day;
}
titleH = DmGetResource (strRsc, endDateTitleStrID);
titleP = (Char*) MemHandleLock (titleH);
if (SelectDay (selectDayByDay, &month, &day, &year, titleP))
{
RepeatEndDate.day = day;
RepeatEndDate.month = month;
RepeatEndDate.year = year - firstYear;
// Make sure the end date is not before the start date.
if (DateToInt(RepeatEndDate) < DateToInt (details->when.date))
{
SndPlaySystemSound (sndError);
DateToInt (RepeatEndDate) = apptNoEndDate;
}
}
MemHandleUnlock (titleH);
}
RepeatSetDateTrigger (RepeatEndDate);
}
/***********************************************************************
*
* FUNCTION: RepeatChangeRepeatOn
*
* DESCRIPTION: This routine is called when one of the weekly "repeat on"
* push button is pushed. This routine checks
* if all the buttons has been turned off, if so the day
* of the week of the appointment's start date is turn on.
*
* PARAMETERS: event - pointer to and event
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 7/7/95 Initial Revision
*
***********************************************************************/
static void RepeatChangeRepeatOn (EventType* event)
{
#pragma unused (event)
UInt16 i;
UInt16 id;
UInt16 index;
UInt16 dayOfWeek;
FormPtr frm;
Boolean on;
DetailsPtr details;
// Get the block that contains the details of the current record.
details = RepeatDetailsP;
frm = FrmGetActiveForm ();
// Check if any of the buttons are on.
index = FrmGetObjectIndex (frm, RepeatDayOfWeek1PushButton);
on = false;
for (i = 0; i < daysInWeek; i++)
{
if (FrmGetControlValue (frm, index + i) != 0)
{
on = true;
break;
}
}
// If all the buttons are off, turn on the start date's button.
if (! on)
{
dayOfWeek = DayOfWeek (details->when.date.month,
details->when.date.day,
details->when.date.year+firstYear);
dayOfWeek = (( dayOfWeek -
details->repeat.repeatStartOfWeek + daysInWeek) % daysInWeek);
id = RepeatDayOfWeek1PushButton + dayOfWeek;
CtlSetValue (GetObjectPtr (id), true);
}
// Update the display of the repeat descrition.
RepeatDrawDescription (frm);
}
/***********************************************************************
*
* FUNCTION: RepeatChangeType
*
* DESCRIPTION: This routine changes the ui gadgets in the repeat dialog
* such that they match the newly selected repeat type. The
* routine is called when one of the repeat type push buttons
* are pushed.
*
* PARAMETERS: event - pointer to and event
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 07/07/95 Initial Revision
* gap 10/28/99 End on value maintained last selected date
* after switching repeat type instead of returning to
* "no end date" also reset RepeatEndDate global such that
* if end date is "no end date" and "choose" is selected from
* popup - calendar always defaults to current day.
*
***********************************************************************/
static void RepeatChangeType (EventType* event)
{
UInt16 id;
UInt16 dayOfWeek;
FormPtr frm;
DetailsPtr details;
RepeatType oldType;
RepeatType newType;
RepeatInfoType repeat;
// If the type if monthly default to monthly-by-date.
newType = (RepeatType) (event->data.ctlSelect.controlID - RepeatNone);
if (newType > repeatWeekly) newType++;
oldType = RepeatingEventType;
if (oldType == newType) return;
frm = FrmGetActiveForm ();
// Get the block that contains the details of the current record.
details = RepeatDetailsP;
// Initialize the ui gadgets.
if (newType == details->repeat.repeatType)
{
RepeatSetUIValues (frm, &details->repeat);
// if reselecting current repeat type, reset RepeatEndDate global
// to current date so if user attemps to "choose" a new day, the
// default matches date displayed as opposed to last date picked
// last in choose form
RepeatEndDate = details->repeat.repeatEndDate;
}
else
{
repeat.repeatType = newType;
// when switching to a repeat type different from the current
// setting, always start user with default end date and frequency
// settings.
DateToInt(repeat.repeatEndDate) = defaultRepeatEndDate;
DateToInt(RepeatEndDate) = defaultRepeatEndDate;
repeat.repeatFrequency = defaultRepeatFrequency;
repeat.repeatStartOfWeek = StartDayOfWeek;
if (newType == repeatWeekly)
{
dayOfWeek = DayOfWeek (details->when.date.month,
details->when.date.day,
details->when.date.year+firstYear);
repeat.repeatOn = (1 << dayOfWeek);
}
else if (newType == repeatMonthlyByDay)
{
repeat.repeatOn = DayOfMonth (details->when.date.month,
details->when.date.day,
details->when.date.year + firstYear);
}
else
{
repeat.repeatOn = 0;
}
RepeatSetUIValues (frm, &repeat);
}
// Hide the ui gadgets that are unique to the repeat type we are
// no longer editing.
switch (oldType)
{
case repeatNone:
HideObject (frm, RepeatNoRepeatLabel);
break;
case repeatDaily:
HideObject (frm, RepeatDaysLabel);
break;
case repeatWeekly:
HideObject (frm, RepeatWeeksLabel);
for (id = RepeatRepeatOnLabel; id <= RepeatDayOfWeek7PushButton; id++)
HideObject (frm, id);
break;
case repeatMonthlyByDay:
case repeatMonthlyByDate:
HideObject (frm, RepeatMonthsLabel);
for (id = RepeatByLabel; id <= RepeatByDatePushButon; id++)
HideObject (frm, id);
break;
case repeatYearly:
HideObject (frm, RepeatYearsLabel);
break;
}
// Handle switching to or from "no" repeat.
if (oldType == repeatNone)
{
ShowObject (frm, RepeatEveryLabel);
ShowObject (frm, RepeatFrequenceField);
ShowObject (frm, RepeatEndOnLabel);
ShowObject (frm, RepeatEndOnTrigger);
}
else if (newType == repeatNone)
{
HideObject (frm, RepeatEveryLabel);
HideObject (frm, RepeatFrequenceField);
HideObject (frm, RepeatEndOnLabel);
HideObject (frm, RepeatEndOnTrigger);
}
// Show the ui object that are appropriate for the new repeat
// type.
switch (newType)
{
case repeatNone:
ShowObject (frm, RepeatNoRepeatLabel);
break;
case repeatDaily:
ShowObject (frm, RepeatDaysLabel);
break;
case repeatWeekly:
ShowObject (frm, RepeatWeeksLabel);
ShowObject (frm, RepeatRepeatOnLabel);
for (id = RepeatRepeatOnLabel; id <= RepeatDayOfWeek7PushButton; id++)
ShowObject (frm, id);
break;
case repeatMonthlyByDay:
case repeatMonthlyByDate:
ShowObject (frm, RepeatMonthsLabel);
ShowObject (frm, RepeatByLabel);
ShowObject (frm, RepeatByDayPushButon);
ShowObject (frm, RepeatByDatePushButon);
break;
case repeatYearly:
ShowObject (frm, RepeatYearsLabel);
break;
}
RepeatingEventType = newType;
// Update the display of the repeat descrition.
RepeatDrawDescription (frm);
}
/***********************************************************************
*
* FUNCTION: RepeatApply
*
* DESCRIPTION: This routine applies the changes made in the Repeat Dialog.
* The changes or copied to a block intiialize by the
* Details Dialog, they a not written to the database until
* the Details Dialog is applied.
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 7/24/95 Initial Revision
*
***********************************************************************/
static void RepeatApply (void)
{
DetailsPtr details;
RepeatInfoType repeat;
// Get the block that contains the details of the current record,
// this block was initialized by the details dialog initializtion
// routine.
details = RepeatDetailsP;
RepeatGetUIValues (FrmGetActiveForm (), &repeat);
details->repeat = repeat;
}
/***********************************************************************
*
* FUNCTION: RepeatDescRectHandler
*
* DESCRIPTION: This routine is the event handler for rectangle gadget
* surrounding the repeat description in the "Repeat
* Dialog Box".
*
* Instead of drawing a static rectangle the size of the
* gadget bounds, I have sized the gadget to be the full area
* of the repeat dialog the description field will still fit
* should the field have to be slightly resized for any reason.
* The bounding rect drawn is calculated from the field's
* bounding rect.
*
* PARAMETERS: gadgetP - pointer to the gadget
* cmd - the event type to be handled
* paramp - any additional data that is passed to the gadget
*
* RETURNED: true if the event was handled and should not be passed
* to a higher level handler.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* gap 10/21/99 Initial Revision
*
***********************************************************************/
#ifdef FORM_GADGET_TYPE_IN_CALLBACK_DEFINED // Added for Compatibility with SDK 4.0 update 1
static Boolean RepeatDescRectHandler(FormGadgetTypeInCallback *gadgetP, UInt16 cmd, void *paramP)
#else
static Boolean RepeatDescRectHandler(FormGadgetType *gadgetP, UInt16 cmd, void *paramP)
#endif
{
FieldPtr fld;
RectangleType r;
switch(cmd)
{
case formGadgetEraseCmd:
case formGadgetDrawCmd:
// get the repeat description field and calculate a bounding box
fld = GetObjectPtr (RepeatDescField);
FldGetBounds (fld, &r);
RctInsetRectangle (&r, -4);
if (cmd == formGadgetDrawCmd)
WinDrawRectangleFram
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -