static void ExamDelete(void) { MemHandle mex, m; ExamDBRecord *ex; UInt16 index=0, pressedButton=0; Char *courseName, timeTemp[timeStringLength], dateTemp[longDateStrLength]; DmFindRecordByID(DatabaseGetRefN(DB_MAIN), gExamsLastSelRowUID, &index); mex = DmQueryRecord(DatabaseGetRefN(DB_MAIN), index); ex = (ExamDBRecord *)MemHandleLock(mex); m=MemHandleNew(1); CourseGetName(ex->course, &m, true); courseName = MemHandleLock(m); DateToAscii(ex->date.month, ex->date.day, ex->date.year+MAC_SHIT_YEAR_CONSTANT, PrefGetPreference(prefLongDateFormat), dateTemp); TimeToAscii(ex->begin.hours, ex->begin.minutes, PrefGetPreference(prefTimeFormat), timeTemp); pressedButton = FrmCustomAlert(ALERT_ex_dodel, courseName, dateTemp, timeTemp); MemHandleUnlock(m); MemHandleFree(m); MemHandleUnlock(mex); if (pressedButton == 0) { // OK, the user really wants us to delete the record NoteDelete(&index); DmRemoveRecord(DatabaseGetRefN(DB_MAIN), index); gExamsSelRow=0; FrmUpdateForm(FORM_exams, frmRedrawUpdateCode); } }
bool_t GetIsDst(datetime_t t) { UInt32 ot = DateTimeToPalm(t); return TimUTCToTimeZone(ot, PrefGetPreference(prefTimeZone), 0) != TimUTCToTimeZone(ot, PrefGetPreference(prefTimeZone), PrefGetPreference(prefDaylightSavingAdjustment)); }
struct tm *localtime(const time_t *timer) { static struct tm tmDate; DateTimeType dt; UInt32 secs = *timer; // get ROM version UInt32 romVersion; Err e = FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion); // form 1/1/1904 12AM to 1/1/1970 12AM DateTimeType Epoch = {0, 0, 0, 1, 1, 1970, 0}; // timer supposed to be based on Epoch secs += TimDateTimeToSeconds(&Epoch); // DST really supported from OS v4.0 if (romVersion >= sysMakeROMVersion(4,0,0,sysROMStageRelease,0)) secs += (PrefGetPreference(prefTimeZone) + PrefGetPreference(prefDaylightSavingAdjustment)) * 60; else secs += (PrefGetPreference(prefMinutesWestOfGMT) - 720) * 60; // no sure about this one TimSecondsToDateTime (secs, &dt); tmDate.tm_sec = dt.second; tmDate.tm_min = dt.minute; tmDate.tm_hour = dt.hour; tmDate.tm_mday = dt.day; tmDate.tm_mon = dt.month - 1; tmDate.tm_year = dt.year - 1900; tmDate.tm_wday = dt.weekDay; return &tmDate; }
static void TableDrawData(void *table, Int16 row, Int16 column, RectangleType *bounds) { UInt16 index=TblGetRowID(table, row); ExamDBRecord *ex; MemHandle mex; RGBColorType fore={0x00, 0x00, 0x00, 0x00}, back={0x00, 0xFF, 0xFF, 0xFF}; if (! TblRowUsable(table, row)) return; TNSetBackColorRGB(&back, NULL); TNSetForeColorRGB(&back, NULL); WinDrawRectangle(bounds, 0); mex = DmQueryRecord(DatabaseGetRefN(DB_MAIN), index); ex = (ExamDBRecord *)MemHandleLock(mex); if (column == EXCOL_COURSE) { Char *temp; MemHandle m=MemHandleNew(1); CourseGetName(ex->course, &m, true); temp = MemHandleLock(m); TNSetForeColorRGB(&fore, NULL); TNDrawCharsToFitWidth(temp, bounds); MemHandleUnlock(m); MemHandleFree(m); } else if (column == EXCOL_NOTE) { if (ex->note) { Char noteSymb[2] = { GADGET_NOTESYMBOL, 0 }; FontID oldFont = FntSetFont(symbolFont); TNDrawCharsToFitWidth(noteSymb, bounds); FntSetFont(oldFont); } } else if (column == EXCOL_DATE) { Char dateTemp[dateStringLength]; DateToAscii(ex->date.month, ex->date.day, ex->date.year+MAC_SHIT_YEAR_CONSTANT, PrefGetPreference(prefDateFormat), dateTemp); TNDrawCharsToFitWidth(dateTemp, bounds); } else if (column == EXCOL_TIME) { Char timeTemp[timeStringLength]; TimeToAscii(ex->begin.hours, ex->begin.minutes, PrefGetPreference(prefTimeFormat), timeTemp); TNDrawCharsToFitWidth(timeTemp, bounds); } if (ex->flags & EX_FLAG_DONE) { RGBColorType red = {0x00, 0xFF, 0x00, 0x00}, old; Int16 yCoord=bounds->topLeft.y+(bounds->extent.y / 2); TNSetForeColorRGB(&red, &old); WinDrawLine(bounds->topLeft.x, yCoord, bounds->topLeft.x+bounds->extent.x, yCoord); TNSetForeColorRGB(&old, NULL); } MemHandleUnlock(mex); }
struct tm * localtime_r (const time_t *pt, struct tm *ptm) { UInt32 utcTime; Int16 timeZone = PrefGetPreference(prefTimeZone); Int16 daylightSavingAdjustment = PrefGetPreference(prefDaylightSavingAdjustment); if ((NULL == pt) || (NULL == ptm)) { return NULL; } utcTime = TimUTCToTimeZone (*pt + SEC_1904_1970, timeZone, daylightSavingAdjustment); palmtimet2unixtm (utcTime, ptm); return ptm; }
/*********************************************************************** * * FUNCTION: PrvSetTimeField * * DESCRIPTION: Set the given field's text to show a time and day of week. * * PARAMETERS: frm - a pointer to the form containing the field to set * timeFieldID - the ID of the field to set * timeHandle - the handle used for storing the text for this field * time - a pointer to the date and time to show in the field * drawField - whether to draw field after setting its text * * RETURNED: nothing * * REVISION HISTORY: * Name Date Description * ---- ---- ----------- * peter 3/7/00 Initial Revision * ***********************************************************************/ static void PrvSetTimeField(FormType * frm, UInt16 timeFieldID, MemHandle timeHandle, DateTimeType *time, Boolean drawField) { FieldType * timeFieldP; Char * timeString, * timeZoneDOWFormatString, * currentDOWString; MemHandle resHandle; TimeFormatType timeFormat; // Format to display time in timeFormat = (TimeFormatType)PrefGetPreference(prefTimeFormat); timeString = MemHandleLock(timeHandle); TimeToAscii(time->hour, time->minute, timeFormat, timeString); currentDOWString = timeString + StrLen(timeString); currentDOWString[0] = ' '; currentDOWString++; resHandle = DmGetResource(strRsc, DOWformatString); ErrNonFatalDisplayIf(resHandle == NULL, "Missing string resource"); timeZoneDOWFormatString = MemHandleLock(resHandle); DateTemplateToAscii(timeZoneDOWFormatString, time->month, time->day, time->year, currentDOWString, dowLongDateStrLength); MemHandleUnlock(resHandle); MemHandleUnlock(timeHandle); timeFieldP = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, timeFieldID)); FldSetTextHandle(timeFieldP, timeHandle); if (drawField) FldDrawField(timeFieldP); }
/******************************************************************************** * Function: StartApplication * Description: This is the first function that gets called and it is * responsible for initializing databases and other global variables, checking * to see whether private records will be shown and calculating the auto-off time * for the current system. * ******************************************************************************/ static Err StartApplication (void) { UInt16 mode = dmModeReadWrite; Err errors = 0; Boolean created; StripPrefType prefs; UInt16 prefsSize, prefsVersion; // set current form to be the password opener currentForm = PasswordForm; // check about private records hideSecretRecords = PrefGetPreference (prefHidePrivateRecordsV33); if (!hideSecretRecords) mode |= dmModeShowSecret; /* handle program prefrences */ prefsSize = sizeof (StripPrefType); prefsVersion = PrefGetAppPreferences (StripCreator, StripPrefID, &prefs, &prefsSize, true); if (prefsVersion == noPreferenceFound) { FrmCustomAlert (GenericError, "This version of StripCS is only able to convert 0.5 databases. If you're using an earlier version you must run the StripCS_0.5.prc file that came with this distro first. If you aren't upgrading, just run Strip.prc!", NULL, NULL); return -1; } else if (prefsVersion == StripVersionNumber) { FrmCustomAlert (GenericError, "It looks like you have already converted your databases with StripCS. You may now use the latest version of Strip.", NULL, NULL); return -1; } // open or create databases. errors = getDatabase (&SystemDB, systemDBTypeOld, StripCreator, mode, 0, systemDBName, &created); errors = getDatabase (&AccountDB, accountDBTypeOld, StripCreator, mode, 0, accountDBName, &created); errors = getDatabase (&PasswordDB, passwordDBTypeOld, StripCreator, mode, 0, passwordDBName, &created); // if the password database does not exist, or there are no records in it note that // this is the first run, so the user will be prompted to enter a new password. if (created ||(DmNumRecordsInCategory (PasswordDB, dmAllCategories) == 0)) { firstRun = true; } // set up the timer stuff. start by setting auto off time to 0. the function returns the old // auto off time. If the oldAutoOffTime is 0 then the system will never shut down. this is not // the behavior that we want, so we reset the autoOffTime to 300. if the oldAutoOffTime is not // 0 then we set it back immediatly. Note that in the StopApplication function we // set the autoOffTime back to what it was before this program started no matter what. return 0; }
datetime_t TimePackToRel(const datepack_t *tp, bool_t Local) { DateTimeType Date; UInt32 ot; if (!tp) return INVALID_DATETIME_T; Date.second = (int16_t)tp->Second; Date.minute = (int16_t)tp->Minute; Date.hour = (int16_t)tp->Hour; Date.day = (int16_t)tp->Day; Date.month = (int16_t)tp->Month; Date.year = (int16_t)tp->Year; Date.weekDay = (int16_t)(tp->WeekDay-1); ot = TimDateTimeToSeconds(&Date); if (Local) ot = TimTimeZoneToUTC(ot, PrefGetPreference(prefTimeZone), PrefGetPreference(prefDaylightSavingAdjustment)); return PalmToDateTime(ot); }
bool_t GetDatePacked(datetime_t t, datepack_t *tp, bool_t Local) { DateTimeType Date; UInt32 ot; if (!tp || t == INVALID_DATETIME_T) return 0; memset(&Date, 0, sizeof(DateTimeType)); ot = DateTimeToPalm(t); if (Local) ot = TimUTCToTimeZone(ot, PrefGetPreference(prefTimeZone), PrefGetPreference(prefDaylightSavingAdjustment)); TimSecondsToDateTime(ot, &Date); tp->Second = Date.second; tp->Minute = Date.minute; tp->Hour = Date.hour; tp->Day = Date.day; tp->Month = Date.month; tp->Year = Date.year; tp->WeekDay = Date.weekDay; return 1; }
time_t time(time_t *tloc) { // get ROM version UInt32 romVersion; Err e = FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion); // since 1/1/1904 12AM. UInt32 secs = TimGetSeconds(); // form 1/1/1904 12AM to 1/1/1970 12AM DateTimeType Epoch = {0, 0, 0, 1, 1, 1970, 0}; secs -= TimDateTimeToSeconds(&Epoch); // DST really supported from OS v4.0 if (romVersion >= sysMakeROMVersion(4,0,0,sysROMStageRelease,0)) secs -= (PrefGetPreference(prefTimeZone) + PrefGetPreference(prefDaylightSavingAdjustment)) * 60; else secs -= (PrefGetPreference(prefMinutesWestOfGMT) - 720) * 60; if (tloc) *tloc = secs; return (secs); }
inline static Err WordLookupRenderStatusText(const char* word, ConnectionStage stage, UInt16 bytesReceived, const char* baseText, ExtensibleBuffer& statusText) { Err error=errNone; char* text=TxtParamString(baseText, word, NULL, NULL, NULL); if (NULL==text) return memErrNotEnoughSpace; ebufResetWithStr(&statusText, text); MemPtrFree(text); if (stageReceivingResponse==stage) { static const UInt16 bytesBufferSize=28; // it will be placed in code segment, so no worry about globals char buffer[bytesBufferSize]; Int16 bytesLen=0; if (bytesReceived<1024) bytesLen=StrPrintF(buffer, " %d bytes", bytesReceived); else { UInt16 bri=bytesReceived/1024; UInt16 brf=((bytesReceived%1024)+51)/102; // round to 1/10 Assert(brf<=10); if (brf==10) { bri++; brf=0; } char formatString[10]; StrCopy(formatString, " %d.%d kB"); NumberFormatType numFormat=static_cast<NumberFormatType>(PrefGetPreference(prefNumberFormat)); char dontCare; LocGetNumberSeparators(numFormat, &dontCare, formatString+3); // change decimal separator in place bytesLen=StrPrintF(buffer, formatString, bri, brf); } Assert(bytesLen<bytesBufferSize); if (bytesLen>0) ebufAddStrN(&statusText, buffer, bytesLen); } ebufAddChar(&statusText, chrNull); return error; }
/* SoundLevelType: slOn, slOff gameSoundLevel found in SystemPreferencesType */ void do_feep(Long frq, UInt dur) { SystemPreferencesChoice allgamesound; if (!my_prefs.sound) return; #ifdef I_AM_OS_2 allgamesound = prefGameSoundLevel; #else allgamesound = prefGameSoundLevelV20; #endif if (PrefGetPreference(allgamesound) != slOff) { /* click: 200, 9 confirmation: 500, 70 */ SndCommandType sndCmd; sndCmd.cmd = sndCmdFreqDurationAmp; /* "play a sound" */ sndCmd.param1 = frq; /* frequency in Hz */ sndCmd.param2 = dur; /* duration in milliseconds */ sndCmd.param3 = sndDefaultAmp; /* amplitude (0 to sndMaxAmp) */ SndDoCmd(0, &sndCmd, true); } }
/*********************************************************************** * * FUNCTION: RepeatSetDateTrigger * * DESCRIPTION: This routine sets the label of the trigger that displays * the end date of a repeating appointment. * * PARAMETERS: endDate - date or -1 if no end date * * RETURNED: nothing * * NOTES: * This routine assumes that the memory allocated for the label of * the due date trigger is large enough to hold the lagest posible * label. This label's memory is reserved by initializing the label * in the resource file. * ***********************************************************************/ static void RepeatSetDateTrigger (DateType endDate) { FormType* frm = FrmGetFormPtr(RepeatForm); ListType* lst = GetObjectPointer(frm, RepeatEndOnList); ControlType* ctl = GetObjectPointer(frm, RepeatEndOnTrigger); Char* label = (Char*)CtlGetLabel(ctl); /* OK to cast; we call CtlSetLabel */ ASSERT(lst); ASSERT(ctl); ASSERT(label); if (DateToInt(endDate) == apptNoEndDate) { StrCopy(label, LstGetSelectionText(lst, repeatNoEndDateItem)); LstSetSelection(lst, noEndDateItem); } else { /* Format the end date into a string. */ DateToDOWDMFormat(endDate.month, endDate.day, endDate.year + firstYear, PrefGetPreference(prefDateFormat), label); LstSetSelection(lst, repeatChooseDateItem); } CtlSetLabel(ctl, label); }
/*********************************************************************** * * FUNCTION: RepeatGetUIValues * * DESCRIPTION: This routine gets the current repeat settings of the * ui gadgets in the repeat dialog box * * * PARAMETERS: frm - pointer to the repeat dialog * repeatP - RepeatInfoType structure (fill-in by this routine) * * RETURNED: nothing * ***********************************************************************/ void RepeatGetUIValues (FormType* frm, RepeatInfoType* repeatP) { UInt16 freq; UInt16 i; UInt16 id; UInt16 index; Char* str = NULL; /* Get the repeat type. */ index = FrmGetControlGroupSelection(frm, RepeatTypeGroup); id = FrmGetObjectId(frm, index); if (id == RepeatYearly) { repeatP->repeatType = repeatYearly; } else if (id <= RepeatWeekly) { repeatP->repeatType = (RepeatType) (id - RepeatNone); } else { index = FrmGetControlGroupSelection(frm, RepeatByGroup); id = FrmGetObjectId(frm, index); if (id == RepeatByDayPushButton) repeatP->repeatType = repeatMonthlyByDay; else repeatP->repeatType = repeatMonthlyByDate; } /* Get the repeat end date. */ repeatP->repeatEndDate = d.repeat_end_date; /* Get the repeat frequency. */ str = FldGetTextPtr(GetObjectPointer(frm, RepeatFrequenceField)); if (str) freq = StrAToI(str); else freq = 0; if (freq) repeatP->repeatFrequency = freq; else repeatP->repeatFrequency = 1; /* ** Get the start day of week. If the original repeat type, that is the ** repeat type when the dialog was first displayed, is weekly then ** use the start date in the repeat info (the unedit data), otherwise ** use the current start of week. */ if (repeatP->repeatType == repeatWeekly) { if (d.tmp_repeat.repeatType == repeatWeekly) repeatP->repeatStartOfWeek = d.tmp_repeat.repeatStartOfWeek; else repeatP->repeatStartOfWeek = PrefGetPreference(prefWeekStartDay); } else { /* For all other repeat types, the repeatStartOfWeek field is meaningless. */ repeatP->repeatStartOfWeek = 0; } /* If the repeat type is weekly, get the day of the week the event repeats on. */ if (repeatP->repeatType == repeatWeekly) { repeatP->repeatOn = 0; index = FrmGetObjectIndex(frm, RepeatDayOfWeek1PushButton); for (i = 0; i < daysInWeek ; i++) { if (FrmGetControlValue(frm, index + ((i - d.repeat_start_of_week + daysInWeek) % daysInWeek))) repeatP->repeatOn |= (1 << i); } } else if (repeatP->repeatType == repeatMonthlyByDay) { /* ** If the repeat type is monthly by day, get the day of the month (ex: ** first Friday) of the start date of the event. */ if (d.tmp_repeat.repeatType == repeatMonthlyByDay) repeatP->repeatOn = d.tmp_repeat.repeatOn; else repeatP->repeatOn = DayOfMonth (d.frm_date.month, d.frm_date.day, d.frm_date.year); } else { /* For all other repeat types, the repeatOn field is meaningless. */ repeatP->repeatOn = 0; } }
static void ExamDetailsSetTriggers(ControlType *dtr, ControlType *ttr) { DateToAscii(gExamDetailsDate.month, gExamDetailsDate.day, gExamDetailsDate.year+MAC_SHIT_YEAR_CONSTANT, PrefGetPreference(prefLongDateFormat), gExamDetailsDateTrigger); CtlSetLabel(dtr, gExamDetailsDateTrigger); // Time Trigger not longer set, done during EditTimeGetTime call }
/***************************************************************************** * Function: GadgetGetTimeFormat * * Description: Returns current TimeFormat *****************************************************************************/ TimeFormatType GadgetGetTimeFormat(void) { return (TimeFormatType) PrefGetPreference(prefTimeFormat); }
/*********************************************************************** * * 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 * ***********************************************************************/ static void RepeatChangeType(EventType* event) { UInt16 id; FormType* frm = FrmGetFormPtr(RepeatForm); const RepeatType oldType = d.repeat_event_type; 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++; if (oldType == newType) return; /* Initialize the UI gadgets. */ if (newType == d.tmp_repeat.repeatType) { RepeatSetUIValues(frm, &d.tmp_repeat); /* ** If reselecting current repeat type, reset d.repeat_end_date 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. */ d.repeat_end_date = d.tmp_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(d.repeat_end_date) = defaultRepeatEndDate; repeat.repeatFrequency = defaultRepeatFrequency; repeat.repeatStartOfWeek = PrefGetPreference(prefWeekStartDay); if (newType == repeatWeekly) { repeat.repeatOn = (1 << DayOfWeek(d.frm_date.month, d.frm_date.day, d.frm_date.year/*+firstYear*/)); } else if (newType == repeatMonthlyByDay) { repeat.repeatOn = DayOfMonth(d.frm_date.month, d.frm_date.day, d.frm_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 repeatHourly: HideObject(frm, RepeatHoursLabel); 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 <= RepeatByDatePushButton; 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 repeatHourly: ShowObject(frm, RepeatHoursLabel); 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, RepeatByDayPushButton); ShowObject(frm, RepeatByDatePushButton); break; case repeatYearly: ShowObject(frm, RepeatYearsLabel); break; } d.repeat_event_type = newType; /* Update the display of the repeat descrition. */ RepeatDrawDescription(frm); }
/*********************************************************************** * * FUNCTION: SelectOneTime * * DESCRIPTION: Display a form showing a time and allow the user * to select a different time. This is the single time * dialog as seen in general panel * * PARAMETERS: hour - pointer to hour to change minute - pointer to minute to change * title - string title for the dialog * * RETURNED: true if the OK button was pressed * if true the parameters passed are changed * * REVISION HISTORY: * Name Date Description * ---- ---- ----------- * roger 12/2/94 Initial Revision in General Panel * gavin 3/20/98 Extracted into separate system function * ***********************************************************************/ Boolean SelectOneTime(Int16 *hour,Int16 *minute, const Char * titleP) { FormType * originalForm, * frm; EventType event; Boolean confirmed = false; Boolean handled = false; Boolean done = false; TimeFormatType timeFormat; // Format to display time in Int16 curHour; UInt16 currentTimeButton; UInt8 hoursTimeButtonValue; Char hoursTimeButtonString[3]; UInt8 minuteTensButtonValue; Char minuteTensButtonString[2]; UInt8 minuteOnesButtonValue; Char minuteOnesButtonString[2]; Char separatorString[3]; timeFormat = (TimeFormatType)PrefGetPreference(prefTimeFormat); originalForm = FrmGetActiveForm(); frm = (FormType *) FrmInitForm (SelectOneTimeDialog); if (titleP) FrmSetTitle (frm, (Char *) titleP); FrmSetActiveForm (frm); curHour = *hour; if (Use24HourFormat(timeFormat)) { // Hide the AM & PM ui FrmHideObject (frm, FrmGetObjectIndex (frm, timeAMCheckbox)); FrmHideObject (frm, FrmGetObjectIndex (frm, timePMCheckbox)); } else { if (curHour < 12) CtlSetValue(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, timeAMCheckbox)), true); else { CtlSetValue(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, timePMCheckbox)), true); curHour -= 12; } if (curHour == 0) curHour = 12; } // Set the time seperator to the system defined one separatorString[0] = TimeSeparator(timeFormat); separatorString[1] = '\0'; FrmCopyLabel(frm, timeSeparatorLabel, separatorString); // Now set the time displayed in the push buttons. hoursTimeButtonValue = curHour; StrIToA(hoursTimeButtonString, hoursTimeButtonValue); CtlSetLabel(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, timeHourButton)), hoursTimeButtonString); minuteTensButtonValue = *minute / 10; StrIToA(minuteTensButtonString, minuteTensButtonValue); CtlSetLabel(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, timeMinutesTensButton)), minuteTensButtonString); minuteOnesButtonValue = *minute % 10; StrIToA(minuteOnesButtonString, minuteOnesButtonValue); CtlSetLabel(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, timeMinutesOnesButton)), minuteOnesButtonString); // Set the hour time button to be the one set by the arrows currentTimeButton = defaultTimeButton; CtlSetValue(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, defaultTimeButton)), true); FrmDrawForm (frm); while (!done) { EvtGetEvent (&event, evtWaitForever); if (! SysHandleEvent ((EventType *)&event)) FrmHandleEvent (frm,&event); if (event.eType == ctlSelectEvent) { switch (event.data.ctlSelect.controlID) { case timeOkButton: frm = FrmGetActiveForm(); // Set the new time (seconds are cleared). if (Use24HourFormat(timeFormat)) *hour = hoursTimeButtonValue; else { *hour = hoursTimeButtonValue % 12 + // 12am is 0 hours! (CtlGetValue(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, timePMCheckbox))) ? 12 : 0); } *minute = minuteTensButtonValue * 10 + minuteOnesButtonValue; done = true; confirmed = true; break; case timeCancelButton: done = true; break; case timeDecreaseButton: case timeIncreaseButton: frm = FrmGetActiveForm(); switch (currentTimeButton) { // MemHandle increasing and decreasing the time for each time digit case timeHourButton: if (event.data.ctlSelect.controlID == timeDecreaseButton) { if (Use24HourFormat(timeFormat)) if (hoursTimeButtonValue > 0) hoursTimeButtonValue--; else hoursTimeButtonValue = 23; else if (hoursTimeButtonValue > 1) hoursTimeButtonValue--; else hoursTimeButtonValue = 12; } else { if (Use24HourFormat(timeFormat)) if (hoursTimeButtonValue < 23) hoursTimeButtonValue++; else hoursTimeButtonValue = 0; else if (hoursTimeButtonValue < 12) hoursTimeButtonValue++; else hoursTimeButtonValue = 1; } StrIToA(hoursTimeButtonString, hoursTimeButtonValue); CtlSetLabel(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, timeHourButton)), hoursTimeButtonString); break; case timeMinutesTensButton: if (event.data.ctlSelect.controlID == timeDecreaseButton) { if (minuteTensButtonValue > 0) minuteTensButtonValue--; else minuteTensButtonValue = 5; } else { if (minuteTensButtonValue < 5) minuteTensButtonValue++; else minuteTensButtonValue = 0; } StrIToA(minuteTensButtonString, minuteTensButtonValue); CtlSetLabel(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, timeMinutesTensButton)), minuteTensButtonString); break; case timeMinutesOnesButton: if (event.data.ctlSelect.controlID == timeDecreaseButton) { if (minuteOnesButtonValue > 0) minuteOnesButtonValue--; else minuteOnesButtonValue = 9; } else { if (minuteOnesButtonValue < 9) minuteOnesButtonValue++; else minuteOnesButtonValue = 0; } StrIToA(minuteOnesButtonString, minuteOnesButtonValue); CtlSetLabel(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, timeMinutesOnesButton)), minuteOnesButtonString); break; } handled = true; break; // timeDecreaseButton & timeIncreaseButton case timeHourButton: currentTimeButton = timeHourButton; break; case timeMinutesTensButton: currentTimeButton = timeMinutesTensButton; break; case timeMinutesOnesButton: currentTimeButton = timeMinutesOnesButton; break; } } else if (event.eType == appStopEvent) { EvtAddEventToQueue (&event); done = true; break; } } // end while true FrmEraseForm (frm); FrmDeleteForm (frm); FrmSetActiveForm(originalForm); return (confirmed); }
/*********************************************************************** * * FUNCTION: SelectTime * * DESCRIPTION: Display a form showing a start and end time. * Allow the user to change the time and then * return them. * pTimeDiff. * * PARAMETERS: pStartTime - pointer to TimeType * pEndTime - pointer to TimeType * untimed - true if there isn't a time. * title - string containing the title * startOfDay - used when "All Day" button selected. * endOfDay - our used when "All Day" button selected. * startOfDisplay - first hour initially visible * * RETURNED: True if the time was changed by the user. * The first three parameters may change. * * REVISION HISTORY: * Name Date Description * ---- ---- ----------- * roger 12/2/94 Initial Revision * trev 08/12/97 made non modified passed variables constant * css 06/08/99 added new parameter & "All Day" button for gromit change. * ***********************************************************************/ Boolean SelectTime (TimeType * startTimeP, TimeType * endTimeP, Boolean untimed, const Char * titleP, Int16 startOfDay, Int16 endOfDay, Int16 startOfDisplay) { Int16 firstHour; Char startTimeText [timeStringLength]; Char endTimeText [timeStringLength]; Char timeChars [timeStringLength]; TimePtr timeP; FormType *originalForm, *frm; ListPtr hoursLst, minutesLst; ControlPtr startTimeCtl, endTimeCtl; EventType event; Boolean confirmed = false; MemHandle hoursItems; TimeType startTime, endTime, timeDiff; TimeFormatType timeFormat; ChangingTimeType changingTime; // Get the time format from the system preerances; timeFormat = (TimeFormatType)PrefGetPreference(prefTimeFormat); // Because this routine only deals with minutes in five minute // intervals we convert the proposed times from those passed. startTime.hours = startTimeP->hours; startTime.minutes = startTimeP->minutes; endTime.hours = endTimeP->hours; endTime.minutes = endTimeP->minutes; TimeDifference (&endTime, &startTime, &timeDiff); // Make sure the end time is displayable (clips at 11:55 pm) AdjustTimes (&startTime, &endTime, &timeDiff, changingStartTime); // Clear the buffer that holds written characters. *timeChars = 0; startOfDisplay = min (startOfDisplay, 12); originalForm = FrmGetActiveForm(); frm = (FormType *) FrmInitForm (TimeSelectorForm); FrmSetActiveForm (frm); hoursLst = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorHourList)); minutesLst = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorMinuteList)); startTimeCtl = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorStartTimeButton)); endTimeCtl = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorEndTimeButton)); // Set list to use either 12 or 24 hour time hoursItems = SysFormPointerArrayToStrings ( ((timeFormat == tfColon24h) || (timeFormat == tfDot24h)) ? (Char *) Hours24Array() : (Char *) Hours12Array(), 24); LstSetListChoices (hoursLst, MemHandleLock(hoursItems), 24); LstSetTopItem (hoursLst, startOfDisplay); // Used to do LstMakeItemVisible (hoursLst, startTime.hours); no longer. if (! untimed) { LstSetSelection (hoursLst, startTime.hours); LstSetSelection (minutesLst, startTime.minutes / 5); CtlSetValue (startTimeCtl, true); changingTime = changingStartTime; } else { // The hour list is dynamically created and doesn't have a selection LstSetSelection (minutesLst, noListSelection); changingTime = changingNoTime; } // Set the start and end time buttons to the current times or blank them // if No Time is selected. SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, untimed); // This needs to be taken out when SelectTimeV33 goes away. It allows for backward // compatibility for this change of adding the end of day variable as a parameter. if (endOfDay != noDisplayOfAllDay) { FrmShowObject (frm, FrmGetObjectIndex (frm, TimeSelectorAllDayButton)); } FrmSetTitle (frm, (Char *) titleP); FrmDrawForm (frm); while (true) { EvtGetEvent (&event, evtWaitForever); if (SysHandleEvent ((EventType *)&event)) continue; if (event.eType == appStopEvent) { // Cancel the dialog and repost this event for the app EvtAddEventToQueue(&event); confirmed = false; break; } // Handle these before the form does to overide the default behavior if (changingTime == changingNoTime && event.eType == lstEnterEvent && event.data.lstEnter.listID == TimeSelectorMinuteList) { SndPlaySystemSound(sndError); continue; } FrmHandleEvent (frm, &event); // If the start or end time buttons are pressed then change // the time displayed in the lists. if (event.eType == ctlSelectEvent) { // "Ok" button pressed? if (event.data.ctlSelect.controlID == TimeSelectorOKButton) { confirmed = true; } // "Cancel" button pressed? else if (event.data.ctlSelect.controlID == TimeSelectorCancelButton) { break; } // Start time button pressed? else if (event.data.ctlSelect.controlID == TimeSelectorStartTimeButton) { if (changingTime != changingStartTime) { if (changingTime == changingNoTime) { SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, false); } CtlSetValue (endTimeCtl, false); LstSetSelection (hoursLst, startTime.hours); LstSetSelection (minutesLst, startTime.minutes / 5); changingTime = changingStartTime; } else CtlSetValue(startTimeCtl, true); } // End time button pressed? else if (event.data.ctlSelect.controlID == TimeSelectorEndTimeButton) { if (changingTime != changingEndTime) { if (changingTime == changingNoTime) { SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, false); } CtlSetValue(startTimeCtl, false); LstSetSelection (hoursLst, endTime.hours); LstSetSelection (minutesLst, endTime.minutes / 5); changingTime = changingEndTime; } else CtlSetValue(endTimeCtl, true); } // No time button pressed? else if (event.data.ctlSelect.controlID == TimeSelectorNoTimeButton) { if (changingTime != changingNoTime) { if (changingTime == changingStartTime) CtlSetValue(startTimeCtl, false); else CtlSetValue(endTimeCtl, false); SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, true); LstSetSelection (hoursLst, noListSelection); LstSetSelection (minutesLst, noListSelection); changingTime = changingNoTime; } // Get us out of this form display now. confirmed = true; } // All day button pressed? else if (event.data.ctlSelect.controlID == TimeSelectorAllDayButton) { if (changingTime != changingNoTime) { if (changingTime == changingStartTime) CtlSetValue(startTimeCtl, false); else CtlSetValue(endTimeCtl, false); LstSetSelection (hoursLst, noListSelection); LstSetSelection (minutesLst, noListSelection); changingTime = changingNoTime; } // No matter what, the minutes are 0 for both because only the hour is registered for start/end // times. startTime.minutes = 0; endTime.minutes = 0; startTime.hours = startOfDay; endTime.hours = endOfDay; // Set the times to the new times. SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, true); // Get us out of this form display now. First set the changing time to anything but the changingNoTime value // so that the pointers at the end of this function get set correctly. changingTime = changingStartTime; confirmed = true; } // Clear the buffer that holds written characters. *timeChars = 0; } // If either list is changed then get the new time. If the // start time is changed then change the end time so that the // the time difference remains the same. If the end time is // changed then make sure the end time isn't before the start // time. Also calculate a new time difference. else if (event.eType == lstSelectEvent) { // First, get the info from the list which has changed. if (event.data.lstSelect.listID == TimeSelectorHourList) { if (changingTime == changingStartTime) startTime.hours = (UInt8) LstGetSelection (hoursLst); else if (changingTime == changingEndTime) endTime.hours = (UInt8) LstGetSelection (hoursLst); else if (changingTime == changingNoTime) { startTime.hours = (UInt8) LstGetSelection (hoursLst); SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, false); CtlSetValue (endTimeCtl, false); LstSetSelection (minutesLst, startTime.minutes / 5); changingTime = changingStartTime; } } else if (event.data.lstSelect.listID == TimeSelectorMinuteList) { if (changingTime == changingStartTime) startTime.minutes = (UInt8) LstGetSelection (minutesLst) * 5; else if (changingTime == changingEndTime) endTime.minutes = (UInt8) LstGetSelection (minutesLst) * 5; else if (changingTime == changingNoTime) { ErrNonFatalDisplay("lstEnterEvent not being filtered."); } } if (AdjustTimes (&startTime, &endTime, &timeDiff, changingTime)) { if (changingTime == changingStartTime) { TimeToAscii (startTime.hours, startTime.minutes, timeFormat, startTimeText); CtlSetLabel (startTimeCtl, startTimeText); } else if (changingTime == changingEndTime) { LstSetSelection (hoursLst, startTime.hours); LstSetSelection (minutesLst, startTime.minutes / 5); } } TimeToAscii(endTime.hours, endTime.minutes, timeFormat, endTimeText); CtlSetLabel(endTimeCtl, endTimeText); // Clear the buffer that holds written characters. *timeChars = 0; } // Handle character written in the time picker. else if (event.eType == keyDownEvent) { if (changingTime == changingEndTime) { timeP = &endTime; firstHour = startTime.hours; } else { timeP = &startTime; firstHour = startOfDisplay; } // If a backspace character was written, change the time picker's // current setting to "no-time". if (event.data.keyDown.chr == backspaceChr) { *timeChars = 0; if (changingTime != changingNoTime) { if (changingTime == changingStartTime) CtlSetValue (startTimeCtl, false); else CtlSetValue (endTimeCtl, false); SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, true); LstSetSelection (hoursLst, noListSelection); LstSetSelection (minutesLst, noListSelection); changingTime = changingNoTime; } } // A linefeed character confirms the dialog box. else if (event.data.keyDown.chr == linefeedChr) { confirmed = true; } // If next-field character toggle between start time in end // time. else if (event.data.keyDown.chr == nextFieldChr) { *timeChars = 0; if (changingTime == changingStartTime) { CtlSetValue (startTimeCtl, false); CtlSetValue (endTimeCtl, true); changingTime = changingEndTime; } else { CtlSetValue (endTimeCtl, false); CtlSetValue (startTimeCtl, true); changingTime = changingStartTime; } } // If a valid time character was written, translate the written // character into a time and update the time picker's UI. else if (TranslateTime (timeFormat, event.data.keyDown.chr, firstHour, timeChars, timeP)) { if (changingTime == changingNoTime) { changingTime = changingStartTime; CtlSetValue (startTimeCtl, true); } AdjustTimes (&startTime, &endTime, &timeDiff, changingTime); SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, timeFormat, false); LstSetSelection (hoursLst, timeP->hours); LstSetSelection (minutesLst, timeP->minutes / 5); } } // Has the dialog been confirmed. if (confirmed) { if (changingTime != changingNoTime) { *startTimeP = startTime; *endTimeP = endTime; } else { TimeToInt(*startTimeP) = noTime; TimeToInt(*endTimeP) = noTime; } break; } } FrmEraseForm (frm); FrmDeleteForm (frm); MemHandleFree (hoursItems); FrmSetActiveForm(originalForm); return (confirmed); }
/*********************************************************************** * * FUNCTION: RepeatSetUIValues * * DESCRIPTION: This routine sets the current repeat settings of the * ui gadgets in the repeat dialog box * * PARAMETERS: frm - pointer to the Repeat Dialog * repeatP - pointer to a RepeatInfoType structure. * * RETURNED: nothing * ***********************************************************************/ void RepeatSetUIValues(FormType* frm, RepeatInfoType* repeatP) { UInt16 i; UInt16 id; UInt16 oldFreq; MemHandle freqH; Char* freqP = NULL; Boolean on = false; FieldType* fld = NULL; const Int8 startOfWeek = PrefGetPreference(prefWeekStartDay); /* Set the selection of the "repeat type" push button group. */ id = repeatP->repeatType + RepeatNone; if (repeatP->repeatType > repeatMonthlyByDay) id--; FrmSetControlGroupSelection (frm, RepeatTypeGroup, id); /* Set the frequency field */ if (repeatP->repeatType != repeatNone) { fld = GetObjectPointer(frm, RepeatFrequenceField); freqH = FldGetTextHandle(fld); if (freqH) { freqP = MemHandleLock(freqH); oldFreq = StrAToI(freqP); } else { freqH = MemHandleNew(maxFrequenceFieldLen); ASSERT(freqH); freqP = MemHandleLock(freqH); oldFreq = 0; } if (oldFreq != repeatP->repeatFrequency) { StrIToA(freqP, repeatP->repeatFrequency); FldSetTextHandle(fld, freqH); if (FrmVisible(frm)) { FldEraseField(fld); FldDrawField(fld); } } MemHandleUnlock (freqH); } /* Set the selection of the "repeat on" push button groups. */ if (repeatP->repeatType == repeatWeekly) { /* ** If the appointment has a different start-day-of-week than ** the dialog-box's current start-day-of-week, rearrange the ** labels on the days-of-week push buttons. ** Note that this will only handle button-label shifts of one day. */ if (startOfWeek != d.repeat_start_of_week) { const Char* sundayLabel = CtlGetLabel(GetObjectPointer(frm, RepeatDayOfWeek1PushButton)); for (id = RepeatDayOfWeek1PushButton; id < RepeatDayOfWeek7PushButton; id++) CtlSetLabel(GetObjectPointer(frm, id), CtlGetLabel(GetObjectPointer(frm, id + 1))); CtlSetLabel(GetObjectPointer(frm, RepeatDayOfWeek7PushButton), sundayLabel); d.repeat_start_of_week = startOfWeek; } /* Turn on the push buttons for the days the appointment repeats on. */ for (i = 0; i < daysInWeek; i++) { on = ((repeatP->repeatOn & (1 << i) ) != 0); id = RepeatDayOfWeek1PushButton + ((i - startOfWeek + daysInWeek) % daysInWeek); CtlSetValue(GetObjectPointer(frm, id), on); } } /* Set the selection of the "repeat by" push button groups. */ if (repeatP->repeatType == repeatMonthlyByDate) FrmSetControlGroupSelection(frm, RepeatByGroup, RepeatByDatePushButton); else FrmSetControlGroupSelection(frm, RepeatByGroup, RepeatByDayPushButton); /* Set the "end on" trigger label and popup list selection. */ if (repeatP->repeatType != repeatNone) RepeatSetDateTrigger(repeatP->repeatEndDate); }