/*********************************************************************** * * FUNCTION: RepeatDrawDescription * * DESCRIPTION: This routine draws the text description of the current * repeat type and frequency. * * The description is created from a template string. The * repeat type and frequency determines which template is * used. The template may contain one or more of the * following token: * ^d - day name (ex: Monday) * ^f - frequency * ^x - day of the month ordinal number (ex: 1st - 31th) * ^m - month name (ex: July) * ^w - week ordinal number (1st, 2nd, 3rd, 4th, or last) * * PARAMETERS: frm - pointer to the repeat dialog box * * RETURNED: nothing * ***********************************************************************/ void RepeatDrawDescription(FormType* frm) { UInt8 repeatOn; UInt16 i; UInt16 len; UInt16 freq; UInt16 dayOfWeek; UInt16 templateId = repeatNoneString; UInt16 repeatOnCount = 0; Char* descP = NULL; Char* resP = NULL; Char* saveResP = NULL; MemHandle descH = NULL; MemHandle resH = NULL; RepeatInfoType repeat; FieldType* fld = GetObjectPointer(frm, RepeatDescField); FldEraseField (fld); /* Get the current setting of the repeat ui gadgets. */ RepeatGetUIValues(frm, &repeat); /* ** Determine which template string to use. The template string is ** used to format the description string. Note that we could add ** a soft constant which tells us whether we need to use different ** strings for freq == 1 case (depends on language), thus saving space. */ freq = repeat.repeatFrequency; switch (repeat.repeatType) { case repeatNone: templateId = repeatNoneString; break; case repeatHourly: if (freq == 1) /* "Every hour" */ templateId = everyHourRepeatString; else /* "Every [other | 2nd | 3rd...] hour" */ templateId = hourlyRepeatString; break; case repeatDaily: if (freq == 1) /* "Every day" */ templateId = everyDayRepeatString; else /* "Every [other | 2nd | 3rd...] day" */ templateId = dailyRepeatString; break; case repeatWeekly: if (freq == 1) /* "Every week on [days of week]" */ templateId = everyWeekRepeat1DayString; else templateId = weeklyRepeat1DayString; /* ** Generate offset to appropriate string id, ** based on # of days that we need to append. */ for (i = 0; i < daysInWeek; i++) { if (repeat.repeatOn & (1 << i) ) repeatOnCount++; } templateId += repeatOnCount - 1; break; case repeatMonthlyByDate: if (freq == 1) /* "The ^w ^d of every month" */ templateId = everyMonthByDateRepeatString; else templateId = monthlyByDateRepeatString; break; case repeatMonthlyByDay: if (freq == 1) templateId = everyMonthByDayRepeatString; else templateId = monthlyByDayRepeatString; break; case repeatYearly: if (freq == 1) templateId = everyYearRepeatString; else templateId = yearlyRepeatString; break; default: ErrNonFatalDisplay("Unknown repeat type"); break; } /* ** Allocate a block to hold the description and copy the template ** string into it. */ resH = DmGetResource(strRsc, templateId); resP = MemHandleLock(resH); descH = MemHandleNew(MemPtrSize(resP)); ASSERT(descH); descP = MemHandleLock(descH); StrCopy(descP, resP); MemHandleUnlock(resH); /* Substitute the month name string for the month name token. */ resH = DmGetResource(strRsc, repeatMonthNamesString); resP = MemHandleLock(resH); for (i = 1; i < d.frm_date.month; i++) resP = StrChr(resP, spaceChr) + 1; len = StrChr(resP, spaceChr) - resP; descP = SubstituteStr(descP, monthNameToken, resP, len); MemHandleUnlock(resH); /* Substitute the day name string for the day name token. */ if ((repeatOnCount == 1) || (repeat.repeatType == repeatMonthlyByDay)) templateId = repeatFullDOWNamesString; else templateId = repeatShortDOWNamesString; resH = DmGetResource(strRsc, templateId); resP = MemHandleLock(resH); if (repeat.repeatType == repeatWeekly) { dayOfWeek = repeat.repeatStartOfWeek; repeatOn = repeat.repeatOn; saveResP = resP; while (StrStr (descP, dayNameToken)) { for (i = 0; i < daysInWeek; i++) { if (repeatOn & (1 << dayOfWeek)) { repeatOn &= ~(1 << dayOfWeek); break; } dayOfWeek = (dayOfWeek + 1 + daysInWeek) % daysInWeek; } resP = saveResP; for (i = 0; i < dayOfWeek; i++) resP = StrChr(resP, spaceChr) + 1; len = StrChr(resP, spaceChr) - resP; descP = SubstituteStr(descP, dayNameToken, resP, len); } } else { dayOfWeek = DayOfWeek (d.frm_date.month, d.frm_date.day, d.frm_date.year/* + firstYear*/); for (i = 0; i < dayOfWeek; i++) resP = StrChr(resP, spaceChr) + 1; len = StrChr(resP, spaceChr) - resP; descP = SubstituteStr(descP, dayNameToken, resP, len); } MemHandleUnlock (resH); /* ** Substitute the repeat frequency string for the frequency token. Note that ** we do something special for 2nd (other), since the gender of 'other' changes ** for some languages, depending on whether the next word is day, month, week, ** or year. */ if (freq == 2) { Char otherFreqName[16]; const UInt16 index = repeat.repeatType - repeatNone; SysStringByIndex(freqOrdinal2ndStrlID, index, otherFreqName, sizeof(otherFreqName)); descP = SubstituteStr(descP, frequenceToken, otherFreqName, StrLen(otherFreqName)); } else { resH = DmGetResource(strRsc, freqOrdinalsString); resP = MemHandleLock(resH); for (i = 1; i < freq; i++) resP = StrChr(resP, spaceChr) + 1; len = 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, weekOrdinalsString); resP = MemHandleLock(resH); for (i = 0; i < repeat.repeatOn / daysInWeek; i++) resP = StrChr (resP, spaceChr) + 1; len = 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, dayOrdinalsString); resP = MemHandleLock(resH); for (i = 1; i < d.frm_date.day; i++) resP = StrChr(resP, spaceChr) + 1; len = StrChr(resP, spaceChr) - resP; descP = SubstituteStr(descP, dayOrdinalToken, resP, len); MemHandleUnlock(resH); /* Draw the description. */ MemHandleUnlock(descH); FldFreeMemory(fld); FldSetTextHandle(fld, descH); FldDrawField(fld); }
Boolean DialogGetNames() { FormPtr prevForm, frm; Word hitButton; Boolean retVal = false; CharPtr text; Int i; FieldPtr fp; VoidPtr vPtr; Word oIdx; // Save previous form prevForm = FrmGetActiveForm(); // Init new form frm = FrmInitForm( frmGetNames); // Set it FrmSetActiveForm(frm); // Set Controls for( i = stor.tmpplayers ; i<MaxPlayers ; i++ ) { fp = GetObjectPtr( fieldGetNamesPlayer[i] ); FldSetUsable ( fp, false ); FldEraseField( fp ); ShowControl( fieldGetNamesLabel[i], 0 ); } FrmDrawForm(frm); for( i=0; i < stor.tmpplayers ; i++ ) { SetFieldTextFromStr( fieldGetNamesPlayer[i], stor.player[i].name ); } FrmSetFocus( frm, FrmGetObjectIndex(frm, fieldGetNamesPlayer[0]) ); // Set the handler // FrmSetEventHandler(frm, DialogNewGameHandleEvent); hitButton = FrmDoDialog(frm); // Get Controls if ( hitButton == btn_OK_frmGetNames ) { for( i=0 ; i<stor.tmpplayers ; i++ ) { oIdx = FrmGetObjectIndex( frm, fieldGetNamesPlayer[i]); vPtr = FrmGetObjectPtr( frm, oIdx ); text = FldGetTextPtr( vPtr ); StrCopy( stor.player[i].name, text ); } retVal = true; } // Delete the form, we're not using it FrmDeleteForm(frm); // Restore previous form. if (prevForm) { FrmSetActiveForm(prevForm); } return retVal; }
/*********************************************************************** * * 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); }