Boolean CScoringForm::OnOK(EventPtr pEvent, Boolean& bHandled) { HostTraceOutputTL(sysErrorClass, "OnOK"); gManager->trk->ApplyGamePoints(); gManager->HandleEndOfHand(); if ( gManager->NoWinner() ) { gManager->dealCards(); gManager->Status(GetHandBids); CForm::GotoForm(BiddingForm); EventType event; event.eType = nilEvent; EvtAddEventToQueue (&event); } else { gManager->Status(GameOver); Int16 index = gManager->GetWinner()->playerIndex; gManager->games_won[index]++; CForm::GotoForm(GameOverForm); } HostTraceOutputTL(sysErrorClass, "OnOK done"); bHandled = false; return true; }
Boolean CBiddingForm::OnOpen(EventPtr pEvent, Boolean& bHandled) { InitDisplay(); player_has_bid = false; FormPtr frmP = FrmGetActiveForm(); FrmDrawForm(frmP); // // if the user exited the app from the bidding form, we will // restart the bidding process // GameStatus tmp = gManager->Status(); if ( tmp == SetHandTrump || tmp == GetHandBids ) { gManager->Status(GetHandBids); gManager->NewTrick(false); } // // start bidding to the left of the dealer // gManager->tbl->current_bidder = gManager->getNextPlayerIter(gManager->tbl->dealer); EventType event; event.eType = nilEvent; EvtAddEventToQueue (&event); bHandled = false; return true; }
void wxGUIEventLoop::Exit(int rc) { FrmCloseAllForms(); EventType AppStop; AppStop.eType=appStopEvent; EvtAddEventToQueue(&AppStop); }
/* Emit a key */ void EmitKey( UInt16 key, UInt16 modifiers ) { EventType newEvent; MemSet(&newEvent, sizeof(newEvent), 0); newEvent.eType = keyDownEvent; newEvent.data.keyDown.chr = key; newEvent.data.keyDown.modifiers = modifiers; EvtAddEventToQueue(&newEvent); }
Boolean CGameForm::OnOpen(EventPtr pEvent, Boolean& bHandled) { FrmDrawForm(FrmGetActiveForm()); InitScreen(); DrawLead(); EventType event; event.eType = nilEvent; EvtAddEventToQueue (&event); bHandled = false; return true; }
/* Send a goto event for internal bookmark */ void SendBookmarkGoToEvent ( BookmarkListEntry* listEntry, Boolean returnToForm ) { AnnotationEntry e; UInt16 offset; Header* header; MemHandle handle; EventType match; if ( ! GetAnnotationHeaderByRecordNum( &e, listEntry->recordNum ) ) return; handle = ReturnRecordHandle( e.id.uid ); if ( handle == NULL ) return; header = MemHandleLock( handle ); offset = e.triggerStart + GetParagraphOffset( header, GET_PARAGRAPH( header, e.id.paragraphNum ) ); MemHandleUnlock( handle ); FreeRecordHandle( &handle ); if ( returnToForm ) FrmReturnToForm( GetMainFormId() ); MemSet( &match, sizeof( EventType ), 0 ); match.eType = frmGotoEvent; match.data.frmGoto.formID = GetMainFormId(); match.data.frmGoto.recordNum = e.id.uid; match.data.frmGoto.matchPos = offset; match.data.frmGoto.matchCustom = GOTO_BOOKMARK; EvtAddEventToQueue( &match ); }
Boolean CBiddingForm::OnSetBid(EventPtr pEvent, Boolean& bHandled) { Int16 player_index = (*gManager->tbl->current_bidder)->playerIndex; if ( gManager->Status() == GetHandBids && player_index == gManager->humanIndex && player_has_bid == false ) { FormPtr frmP = FrmGetActiveForm(); UInt16 bidval = 0; if ( CtlGetValue((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid2PushButton ) )) ) { bidval = 2; } else if ( CtlGetValue((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton ) ) ) ){ bidval = 3; } else if ( CtlGetValue((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton ) ) ) ) { bidval = 4; } else if ( CtlGetValue((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidSmudgePushButton ) ) ) ) { bidval = 5; } else { //PlayerBidPassPushButton bidval = 0; } (*gManager->tbl->current_bidder)->Bid(bidval); player_has_bid = true; EventType event; event.eType = nilEvent; EvtAddEventToQueue (&event); } bHandled = false; return true; } // OnSetBid
void OSystem_PalmBase::battery_handler() { // check battery level every 15secs if ((TimGetTicks() - _batCheckLast) > _batCheckTicks) { UInt16 voltage, warnThreshold, criticalThreshold; Boolean pluggedIn; voltage = SysBatteryInfoV20(false, &warnThreshold, &criticalThreshold, NULL, NULL, &pluggedIn); if (!pluggedIn) { if (voltage <= warnThreshold) { if (!_showBatLow) { _showBatLow = true; draw_osd(kDrawBatLow, _screenDest.w - 18, -16, true, 2); displayMessageOnOSD("Battery low."); } } else { if (_showBatLow) { _showBatLow = false; draw_osd(kDrawBatLow, _screenDest.w - 18, -16, false); } } if (voltage <= criticalThreshold) { ::EventType event; event.eType = keyDownEvent; event.data.keyDown.chr = vchrPowerOff; event.data.keyDown.modifiers = commandKeyMask; #if defined(COMPILE_OS5) && defined(PALMOS_ARM) SysEventAddToQueue(&event); #else EvtAddEventToQueue(&event); #endif } } _batCheckLast = TimGetTicks(); } }
/*********************************************************************** * * 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: 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: ThumbnailViewHandleEvent * * DESCRIPTION: This routine is the event handler for the "Thumbnail View" * of the Record application. * * PARAMETERS: event - a pointer to an EventType structure * * RETURNED: true if the event was handled and should not be passed * to a higher level handler. * ***********************************************************************/ Boolean ThumbnailViewHandleEvent (EventPtr event) { FormPtr frm = NULL; Boolean handled = false; switch (event->eType) { case keyDownEvent: /* Hardware button pressed? */ if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr)) { if (!(event->data.keyDown.modifiers & poweredOnKeyMask)) ThumbnailViewNextCategory(); handled = true; } else if (EvtKeydownIsVirtual(event)) { switch (event->data.keyDown.chr) { case vchrPageUp: case vchrRockerUp: if (d.fiveWayNavigation) { /* Deselect previous item */ ToggleButton(d.thumbnailX, d.thumbnailY, false); /* Select new item, scroll if necessary */ if (ThumbnailViewMoveCursorUp()) ThumbnailViewScroll(-1); UpdateButtonAndIndex(); } else { ThumbnailViewPageScroll(winUp); } handled = true; break; case vchrPageDown: case vchrRockerDown: if (d.fiveWayNavigation) { /* Deselect previous item */ ToggleButton(d.thumbnailX, d.thumbnailY, false); /* Select new item, scroll if necessary */ if (ThumbnailViewMoveCursorDown()) ThumbnailViewScroll(1); UpdateButtonAndIndex(); } else { ThumbnailViewPageScroll(winDown); } handled = true; break; /* Treo 600 5-way navigation */ case vchrRockerCenter: handled = ThumbnailViewHandleFiveWayNavSelect(); break; case vchrRockerLeft: handled = ThumbnailViewHandleFiveWayNavLeft(); break; case vchrRockerRight: handled = ThumbnailViewHandleFiveWayNavRight(); break; /* Tungsten 5-way navigation */ case vchrNavChange: if (NavDirectionPressed(event, Left)) handled = ThumbnailViewHandleFiveWayNavLeft(); else if (NavDirectionPressed(event, Right)) handled = ThumbnailViewHandleFiveWayNavRight(); else if (NavSelectPressed(event)) handled = ThumbnailViewHandleFiveWayNavSelect(); break; /* case vchrSendData: */ /* ThumbnailViewDoCommand(ThumbnailRecordBeamCategoryCmd); */ /* handled = true; */ /* break; */ default: /* ignore */ } } break; case ctlSelectEvent: switch (event->data.ctlSelect.controlID) { case NewButton: /* Create new sketch after all existing ones */ p.dbI = DmNumRecords(d.dbR); AllocImage(); FrmGotoForm(p.flags & PFLAGS_WITH_TITLEBAR ? DiddleTForm : DiddleForm); handled = true; break; case CategoryPop: ThumbnailViewSelectCategory(); handled = true; break; case TextListButton: FrmGotoForm(DiddleListForm); handled = true; break; case ThumbnailDetailListButton: FrmGotoForm(DiddleThumbnailDetailForm); handled = true; break; } break; case frmGotoEvent: p.dbI = event->data.frmGoto.recordNum; SwitchCategoryForGoto(); FrmGotoForm(p.flags & PFLAGS_WITH_TITLEBAR ? DiddleTForm : DiddleForm); event->eType = dbOpenRecordFieldEvent; EvtAddEventToQueue(event); handled = true; break; case menuEvent: { Char chr = 0; switch(event->data.menu.itemID) { case menuitemID_CmdAbout: DoAboutDialog(); handled = true; break; case menuitemID_CmdSecurity: ThumbnailDoCmdSecurity(); handled = true; break; case menuitemID_CmdSortByAlarm: case menuitemID_CmdSortByName: if (event->data.menu.itemID == menuitemID_CmdSortByAlarm) DmInsertionSort(d.dbR, &SortByAlarmTime, 0); else DmInsertionSort(d.dbR, &SortByName, 0); SetTopVisibleRecord(0); ThumbnailViewLoadRecords(FrmGetActiveForm()); handled = true; break; case menuitemID_CmdPref: chr=cmdPref; break; case menuitemID_CmdExtPref: chr=cmdExtPref; break; case menuitemID_CmdHWPref: chr=cmdHWPref; break; case menuitemID_CmdAlarmPref: chr=cmdAlarmPref; break; case menuitemID_CmdHelp: chr=cmdHelp; break; } if (!handled) handled = KeyDown(chr); } break; case frmOpenEvent: frm = FrmGetActiveForm(); ThumbnailViewInit(frm); FrmDrawForm(frm); /* Disable 5-way navigation initially */ d.fiveWayNavigation = false; /* Clean up */ if (d.record_name) MemHandleFree(d.record_name); d.record_name = NULL; if (d.record_note) MemHandleFree(d.record_note); d.record_note = NULL; handled = true; break; case frmUpdateEvent: handled = ThumbnailViewUpdateDisplay(event->data.frmUpdate.updateCode); break; case menuCmdBarOpenEvent: MenuCmdBarAddButton(menuCmdBarOnLeft, BarSecureBitmap, menuCmdBarResultMenuItem, menuitemID_CmdSecurity, 0); /* Tell the field package to not add buttons automatically; */ /* we've done it all ourselves. */ event->data.menuCmdBarOpen.preventFieldButtons = true; /* don't set handled to true; this event must fall through to the system. */ break; case sclRepeatEvent: ThumbnailViewScroll (event->data.sclRepeat.newValue - event->data.sclRepeat.value); break; case dbNonKeyCommandEvent: handled = HandleNonKeyCommandCode(event->data.menu.itemID); break; /* case frmObjectFocusTakeEvent: */ /* { */ /* RectangleType r; */ /* FormType* frm = FrmGetFormPtr(event->data.frmObjectFocusTake.formID); */ /* const UInt16 id = event->data.frmObjectFocusTake.objectID; */ /* const UInt16 idx = FrmGetObjectIndex(frm, id); */ /* if (id >= Thumb1 && id <= Thumb30) { */ /* FrmGetObjectBounds(frm, idx, &r); */ /* FrmSetFocus(frm, idx); */ /* HsNavDrawFocusRing(frm, id, hsNavFocusRingNoExtraInfo, &r, */ /* hsNavFocusRingStyleObjectTypeDefault, false); */ /* handled = true; */ /* } */ /* } */ /* break; */ default: /* do nothing */ } return handled; }
Boolean CBiddingForm::OnNilEvent(EventPtr pEvent, Boolean& bHandled) { if ( gManager->Status() == GetHandBids ) { HighlightActiveBidder(); FormPtr frmP = FrmGetActiveForm(); Int16 player_index = (*gManager->tbl->current_bidder)->playerIndex; // // if this is a human player, we need to render the screen widgets for their bid // if ( player_index == gManager->humanIndex && player_has_bid == false ) { player_hand.Render(true); Int16 current_bid = 0; if ( (*gManager->tbl->dealer)->playerIndex != gManager->humanIndex || ! gManager->dealer_take_bid ) { current_bid = gManager->tbl->high_bid; } else { current_bid = gManager->tbl->high_bid - 1; } if ( (*gManager->tbl->dealer)->playerIndex == gManager->humanIndex && gManager->tbl->high_bid < 2 ) { CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), "-4-"); CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), "-3-"); CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidPassPushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidPassPushButton )), "-Pass-"); } else { switch (current_bid) { case 5: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidSmudgePushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBidSmudgePushButton )), "-S-"); case 4: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid4PushButton )), "-4-"); case 3: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid3PushButton )), "-3-"); case 2: CtlSetEnabled((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid2PushButton )), false); CtlSetLabel ((ControlType *)FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, PlayerBid2PushButton )), "-2-"); } } } // if if ( player_index == 3 && player_has_bid == false ) // // handle processing actual bids here - get one automatically if this player isn't // a human, or if the human has already bid // if ( player_index != gManager->humanIndex || player_has_bid == true ) { Boolean player_did_bid = gManager->GetNextBid(gManager->trk, false ); Int16 tmp_bid = (*gManager->tbl->current_bidder)->Bid(); if ( player_did_bid && gManager->tbl->current_bidder == gManager->tbl->winning_bidder && (tmp_bid >= 2) ) { char x[10]; StrPrintF(x, "bids %d", tmp_bid ); bidstr = x; } else { bidstr = "passes"; } bids[(*gManager->tbl->current_bidder)->playerIndex].Replace(bidstr); // // if we just got the dealer's bid, then we are all done // if ( gManager->tbl->current_bidder == gManager->tbl->dealer ) { // // at this point we need to set trump... // gManager->Status(SetHandTrump); if ( (*gManager->tbl->winning_bidder)->playerIndex == gManager->humanIndex ) { CPlayerTrumpForm frmPlayerTrump; frmPlayerTrump.DoModal(); } FrmDrawForm(frmP); // // ... and display the final results // Card::suit_t foo = (*gManager->tbl->winning_bidder)->Trump(); gManager->tbl->trump = foo; gManager->trk->no_trump_first_trick = (*gManager->tbl->winning_bidder)->NoTrumpFirstTrickP(); MemHandle hRsc; BitmapType* bitmapP; switch ( gManager->tbl->trump ) { case Card::heart: hRsc = DmGetResource(bitmapRsc, HeartBitmapFamily ); break; case Card::diamond: hRsc = DmGetResource(bitmapRsc, DiamondBitmapFamily ); break; case Card::club: hRsc = DmGetResource(bitmapRsc, ClubBitmapFamily ); break; case Card::spade: hRsc = DmGetResource(bitmapRsc, SpadeBitmapFamily ); break; } if ( gManager->trk->no_trump_first_trick ) { FrmCustomAlert(NoTrumpFirstTrickAlert, (*gManager->tbl->winning_bidder)->name, "", ""); } RectangleType bounds; UInt16 gadgetIndex = FrmGetObjectIndex(frmP, BiddingTrumpGadget); FrmGetObjectBounds(frmP, gadgetIndex, &bounds); WinPaintChars("Trump Is: ", StrLen("Trump Is: "), bounds.topLeft.x, bounds.topLeft.y ); ErrFatalDisplayIf(!hRsc, "Could not get bitmap family resource"); bitmapP = (BitmapType*) MemHandleLock(hRsc); WinDrawBitmap (bitmapP, bounds.topLeft.x + 40, bounds.topLeft.y); MemHandleUnlock(hRsc); DmReleaseResource(hRsc); UInt32 hsStatusVersion; if (FtrGet (hsFtrCreator, hsFtrIDNavigationSupported, &hsStatusVersion) == 0) { FrmGlueNavObjectTakeFocus(FrmGetActiveForm(), BiddingOKButton ); } } // if ( dealer bid ) else { // move along to the next player gManager->tbl->current_bidder = gManager->getNextPlayerIter(gManager->tbl->current_bidder); EventType event; event.eType = nilEvent; EvtAddEventToQueue (&event); // pause here // SysTaskDelay(SysTicksPerSecond()); gManager->ShortDelay(); } } // if ( player_index != 3 || player_has_bid == true ) } // if GetHandBids bHandled = false; return true; }
void CGameForm::CheckGameCondition() { // // if we're not done with the trick and it's not the // human's turn... // if ( ! gManager->IsTrickOver() && gManager->current != gManager->human ) { DrawLead(); // // then get the played card from everyone up to the human // if ( gManager->GetNextPlay( gManager->trk ) ) { Int16 i = (*gManager->current)->playerIndex; /* if ( i != 0 ) { DrawPlayerHand(i, 0, 0); (*gManager->current)->PlayedCard()->Draw(140, 0, card_width, card_height, false); gManager->LongDelay(); gManager->LongDelay(); } */ gManager->LongDelay(); gManager->NextPlayedCard( (*gManager->current), (*gManager->current)->PlayedCard() ); played_cards.Render(true); } // if ( played card ) if ( gManager->current == gManager->human ) { player_hand.Render(true); } EventType event; event.eType = nilEvent; EvtAddEventToQueue (&event); } // if else { if ( gManager->IsTrickOver() ) { EventType event; event.eType = nilEvent; EvtAddEventToQueue (&event); } } } // CheckGameCondition
/* Perform action assigned to given control object */ void DoControlAction ( const Int16 control /* control value of the object */ ) { UInt16 newRecord; Int16 controlID; /* Clear location of find pattern */ ClearFindPatternData(); if ( 0 < control ) { Int16 anchorIndex; UInt16 reference; Int16 paragraphOffset; Int16 byteOffsetInPara; UInt16 image; AnchorMode type; anchorIndex = control - 1; reference = GetVisibleReference( anchorIndex ); paragraphOffset = GetVisibleParagraphOffset( anchorIndex ); byteOffsetInPara = GetVisibleByteOffset( anchorIndex ); image = GetVisibleImage( anchorIndex ); image = GetVisibleImage( anchorIndex ); type = GetVisibleMode( anchorIndex ); SndPlaySystemSound( sndClick ); if ( image != 0 ) { RectangleType bounds; ListType* list; Int16 x; Int16 y; UInt16 prevCoordSys; Int16 selection; bounds = GetVisibleImagePosition( anchorIndex ); list = GetObjectPtr( frmMainImageDialog ); x = ( bounds.extent.x - 60 ) / 2; if ( x < 0 ) x = 0; y = ( bounds.extent.y - 22 ) / 2; if ( y < 0 ) y = 0; x += bounds.topLeft.x; y += bounds.topLeft.y; LstSetPosition( list, x, y ); prevCoordSys = PalmSetCoordinateSystem( STANDARD ); selection = LstPopupList( list ); PalmSetCoordinateSystem( prevCoordSys ); if ( selection == noListSelection ) { return; } else if ( selection == 1 ) { reference = image; } } if ( type == ANCHORMODE_LINK ) { Int16 byteOffset; if ( byteOffsetInPara == 0 ) { byteOffset = NO_OFFSET; } else { byteOffset = ParagraphNumToByteOffset( paragraphOffset ) + byteOffsetInPara; paragraphOffset = NO_OFFSET; } JumpToRecord( reference, paragraphOffset, byteOffset ); } #ifdef SUPPORT_ANNOTATION else if ( type == ANCHORMODE_ANNOTATION ) { DoAnnotate( GetVisibleAnnotationIdentifier( anchorIndex ), 0, 0, 0, 0, 0, NULL ); } #endif return; } if ( control != 0 ) SndPlaySystemSound( sndClick ); controlID = -( control + 1 ); switch ( controlID ) { case HOMECONTROL: DoAutoscrollToggle( AUTOSCROLL_OFF ); ViewRecord( HOME_PAGE_ID, ADD_TO_HISTORY, 0, 0, WRITEMODE_DRAW_CHAR ); SetVisitedLink( HOME_PAGE_ID ); break; case LEFTCONTROL: DoAutoscrollToggle( AUTOSCROLL_OFF ); newRecord = GetHistoryPrev(); if ( newRecord != NO_RECORD ) { ViewRecord( newRecord, FROM_HISTORY, NO_OFFSET, NO_OFFSET, WRITEMODE_DRAW_CHAR ); SetVisitedLink( newRecord ); } else { FrmGotoForm( GetValidForm( frmLibrary ) ); } break; case RIGHTCONTROL: DoAutoscrollToggle( AUTOSCROLL_OFF ); newRecord = GetHistoryNext(); if ( newRecord != NO_RECORD ) { ViewRecord( newRecord, FROM_HISTORY, NO_OFFSET, NO_OFFSET, WRITEMODE_DRAW_CHAR ); SetVisitedLink( newRecord ); } break; case LIBRARYCONTROL: DoAutoscrollToggle( AUTOSCROLL_OFF ); CloseDocument(); FrmGotoForm( GetValidForm( frmLibrary ) ); break; case FINDCONTROL: DoAutoscrollToggle( AUTOSCROLL_OFF ); FrmPopupForm( frmSearch ); break; case AGAINCONTROL: DoAutoscrollToggle( AUTOSCROLL_OFF ); SearchAgain(); break; case MENUCONTROL: DoAutoscrollToggle( AUTOSCROLL_OFF ); EvtEnqueueKey( menuChr, 0, commandKeyMask ); break; case OFFSETCONTROL: { UInt16 prevCoordSys; Int16 selection; DoAutoscrollToggle( AUTOSCROLL_OFF ); prevCoordSys = PalmSetCoordinateSystem( STANDARD ); selection = LstPopupList( GetObjectPtr( frmMainPercentList ) ); PalmSetCoordinateSystem( prevCoordSys ); if ( selection != noListSelection ) GotoLocation( selection ); break; } case BOOKMARKCONTROL: { UInt16 prevCoordSys; ListType* list; Int16 selection; UInt16 numOfBookmarks; DoAutoscrollToggle( AUTOSCROLL_OFF ); prevCoordSys = PalmSetCoordinateSystem( STANDARD ); list = GetObjectPtr( frmMainBookmarkList ); numOfBookmarks = CreatePopupBookmarkList( list ); if ( numOfBookmarks == 0 ) { PalmSetCoordinateSystem( prevCoordSys ); break; } selection = LstPopupList( GetObjectPtr( frmMainBookmarkList ) ); if ( 0 <= selection ) { BookmarkListEntry e; MemMove( &e, GetBookmarkListEntry( selection ), sizeof( BookmarkListEntry ) ); ReleaseBookmarkList(); PalmSetCoordinateSystem( prevCoordSys ); switch ( e.kind ) { case BOOKMARK_ADD_BOOKMARK: DoAddBookmark(); break; case BOOKMARK_EDIT_BOOKMARK: FrmPopupForm( frmBookmarks ); break; #ifdef SUPPORT_ANNOTATION case BOOKMARK_ADD_ANNOTATION: isSelectWordTapMode = true; selectedWordAction = SELECT_WORD_ANNOTATE; ShowSelectWordTapIcon(); break; #endif case BOOKMARK_BOOKMARK: case BOOKMARK_ANNOTATION: SendBookmarkGoToEvent( &e, false ); break; case BOOKMARK_EXT_BOOKMARK: GoToExtBookmark( e.recordNum ); break; case BOOKMARK_INVALID: break; } } else { ReleaseBookmarkList(); PalmSetCoordinateSystem( prevCoordSys ); } break; } case AUTOSCROLLSTARTCONTROL: case AUTOSCROLLSTOPCONTROL: DoAutoscrollToggle( AUTOSCROLL_TOGGLE ); break; case AUTOSCROLLINCRCONTROL: DoAutoscrollIncr(); break; case AUTOSCROLLDECRCONTROL: DoAutoscrollDecr(); break; case COPYTOMEMOCONTROL: DoHardcopy(); break; #ifdef SUPPORT_WORD_LOOKUP case SELECTEDWORDCONTROL: { EventType newEvent; MemSet( &newEvent, sizeof( newEvent ), 0 ); newEvent.eType = pluckerSelectedWordEvent; newEvent.data.generic.datum[ 0 ] = selectedWordAction; EvtAddEventToQueue( &newEvent ); break; } #endif default: break; } }
/*********************************************************************** * * FUNCTION: SelectTimeZone * * DESCRIPTION: Display a form showing a time zone and allow the user * to select a different time zone. This is the time zone * dialog as seen in Date & Dime panel * * PARAMETERS: * ioTimeZoneP <-> pointer to time zone to change * ioLocaleInTimeZoneP <-> Ptr to locale found in time zone. * titleP -> String title for the dialog. * showTimes -> True => show current and new times * anyLocale -> True => ignore ioLocaleInTimeZoneP on entry. * * RETURNED: * true if the OK button was pressed (in which case *ioTimeZoneP and * *ioCountryInTimeZoneP might be changed). * * HISTORY: * 03/02/00 peter Created by Peter Epstein. * 04/03/00 peter Allow NULL currentTimeP. * 04/12/00 peter API changed to get rid of trigger text * 04/14/00 peter Update current & new time as time passes * 07/31/00 kwk Use SysTicksPerSecond() routine vs. sysTicksPerSecond macro. * kwk Re-wrote to use set of resources (name, offset, country), * scrollbar vs. arrows, etc. * 08/01/00 kwk Support scroll-to-key. Fixed scrollbar/list sync bugs. * 08/02/00 kwk New API w/ioCountryInTimeZoneP and anyCountry parameters. * kwk Call FrmHandleEvent _after_ our event handling code has * decided that it doesn't want to handle the event, not before. * 08/03/00 kwk Call LstSetListChoices before calling LstGetVisibleItems, * as otherwise accessing the time zone picker from the * Setup app (when <showTimes> is false) gives you a two- * line high display because LstGetVisibleItems returns 0. * 08/18/00 kwk Play error sound if user writes letter that doesn't * match any entries. * kwk Don't select item if doing scroll-to-view for entry * that matches the letter the user wrote. * 08/21/00 kwk Scroll-to-view with text entry now scrolls to the top * of the list, versus the middle. * 10/09/00 peter Get rid of scroll bar and let list do the scrolling. * 11/17/00 CS Change ioCountryInTimeZoneP to ioLocaleInTimeZoneP, * (and anyCountry to anyLocale, but that doesn't matter), * since CountryType is only a UInt8, and this may * change someday. * ***********************************************************************/ Boolean SelectTimeZone(Int16 *ioTimeZoneP, LmLocaleType* ioLocaleInTimeZoneP, const Char *titleP, Boolean showTimes, Boolean anyLocale) { FormType* originalForm; FormType* dialog; EventType event; Boolean confirmed = false; Boolean done = false; Boolean adjustTimes = false; Boolean foundLocale = false; MemHandle currentTimeHandle, newTimeHandle; ListPtr listP; Int16 oldTimeZone, newTimeZone, testTimeZone; LmLocaleType newTimeZoneLocale; Int16 delta, closestDelta, timeZoneIndex, closestIndex; DateTimeType currentTime, newTime; TimeZoneEntryType* tzArrayP; UInt16 numTimeZones; MemHandle tzNamesH; if (showTimes) { TimSecondsToDateTime(TimGetSeconds(), ¤tTime); } oldTimeZone = *ioTimeZoneP; newTimeZone = oldTimeZone; newTimeZoneLocale = *ioLocaleInTimeZoneP; originalForm = FrmGetActiveForm(); dialog = (FormType *) FrmInitForm (TimeZoneDialogForm); listP = FrmGetObjectPtr (dialog, FrmGetObjectIndex (dialog, TimeZoneDialogTimeZoneList)); if (titleP) { FrmSetTitle (dialog, (Char *) titleP); } FrmSetActiveForm (dialog); // We need to call LstSetListChoices before calling LstSetHeight below, as otherwise // LstGetVisibleItems will return 0. tzArrayP = PrvCreateTimeZoneArray(&tzNamesH, &numTimeZones); LstSetListChoices(listP, (Char**)tzArrayP, numTimeZones); if (showTimes) { currentTimeHandle = MemHandleNew(timeStringLength + 1 + dowLongDateStrLength + 1); ErrFatalDisplayIf (!currentTimeHandle, "Out of memory"); newTimeHandle = MemHandleNew(timeStringLength + 1 + dowLongDateStrLength + 1); ErrFatalDisplayIf (!newTimeHandle, "Out of memory"); PrvSetTimeField(dialog, TimeZoneDialogCurrentTimeField, currentTimeHandle, ¤tTime, false); } else { // Hide the current and new time. FrmHideObject(dialog, FrmGetObjectIndex (dialog, TimeZoneDialogCurrentTimeLabel)); FrmHideObject(dialog, FrmGetObjectIndex (dialog, TimeZoneDialogCurrentTimeField)); FrmHideObject(dialog, FrmGetObjectIndex (dialog, TimeZoneDialogNewTimeLabel)); FrmHideObject(dialog, FrmGetObjectIndex (dialog, TimeZoneDialogNewTimeField)); // Make the list show more items to take up extra the space. LstSetHeight(listP, LstGetVisibleItems(listP) + extraTimeZonesToShowWhenNoTimes); } // Find the time zone in the list closest to the current time zone, and that // matches <*ioLocaleInTimeZoneP> if <anyLocale> is false. closestDelta = hoursInMinutes * hoursPerDay; // so big that all others will be smaller for (timeZoneIndex = 0; timeZoneIndex < numTimeZones; timeZoneIndex++) { Boolean checkDelta = anyLocale; testTimeZone = tzArrayP[timeZoneIndex].tzOffset; delta = Abs(testTimeZone - oldTimeZone); if (!anyLocale) { if (tzArrayP[timeZoneIndex].tzCountry == ioLocaleInTimeZoneP->country) { // If we haven't previously found a matching locale, reset the // delta so that this entry overrides any previous best entry. if (!foundLocale) { foundLocale = true; closestDelta = hoursInMinutes * hoursPerDay; } checkDelta = true; } // If we haven't yet found a matching locale, go for the closest delta. else { checkDelta = !foundLocale; } } // If we want to check the time zone delta, do it now. if (checkDelta && (delta < closestDelta)) { closestIndex = timeZoneIndex; closestDelta = delta; } } // Scroll so that time zone is in the center of the screen and select it if it's an exact match. LstSetTopItem(listP, max(0, closestIndex - (LstGetVisibleItems(listP) / 2))); if ((closestDelta == 0) && (anyLocale || foundLocale)) { LstSetSelection(listP, closestIndex); if (showTimes) { newTime = currentTime; PrvSetTimeField(dialog, TimeZoneDialogNewTimeField, newTimeHandle, &newTime, false); } } else { LstSetSelection(listP, noListSelection); } LstSetDrawFunction(listP, PrvTimeZoneListDrawItem); FrmDrawForm (dialog); while (!done) { Boolean handled = false; EvtGetEvent(&event, SysTicksPerSecond()); // so we can update the current and new time if (SysHandleEvent ((EventType *)&event)) { continue; } if (event.eType == nilEvent) { if (showTimes) { PrvUpdateTimeFields( dialog, ¤tTime, &newTime, currentTimeHandle, newTimeHandle, TimeZoneDialogCurrentTimeField, TimeZoneDialogNewTimeField); } } else if (event.eType == ctlSelectEvent) { handled = true; switch (event.data.ctlSelect.controlID) { case TimeZoneDialogOKButton: // Set the new time zone. *ioTimeZoneP = newTimeZone; *ioLocaleInTimeZoneP = newTimeZoneLocale; done = true; confirmed = true; break; case TimeZoneDialogCancelButton: done = true; break; default: ErrNonFatalDisplay("Unknown control in form"); break; } } // User tapped on a time zone in the list. else if (event.eType == lstSelectEvent) { UInt16 localeIndex; ErrNonFatalDisplayIf(event.data.lstSelect.listID != TimeZoneDialogTimeZoneList, "Unknown list in form"); newTimeZone = tzArrayP[event.data.lstSelect.selection].tzOffset; newTimeZoneLocale.country = tzArrayP[event.data.lstSelect.selection].tzCountry; newTimeZoneLocale.language = lmAnyLanguage; if (LmLocaleToIndex(&newTimeZoneLocale, &localeIndex) == errNone) { if (LmGetLocaleSetting( localeIndex, lmChoiceLocale, &newTimeZoneLocale, sizeof(newTimeZoneLocale))) { ErrNonFatalDisplay("Can\'t get locale"); } } adjustTimes = showTimes; handled = true; } else if (event.eType == keyDownEvent) { if (!TxtCharIsHardKey(event.data.keyDown.modifiers, event.data.keyDown.chr)) { // Hard scroll buttons if (EvtKeydownIsVirtual(&event)) { if (event.data.keyDown.chr == vchrPageUp) { handled = true; LstScrollList(listP, winUp, LstGetVisibleItems(listP) - 1); } else if (event.data.keyDown.chr == vchrPageDown) { handled = true; LstScrollList(listP, winDown, LstGetVisibleItems(listP) - 1); } } else if (TxtCharIsPrint(event.data.keyDown.chr)) { Int16 index; handled = true; index = PrvSearchTimeZoneNames(tzArrayP, numTimeZones, event.data.keyDown.chr); if (index != noListSelection) { Int16 delta = index - listP->topItem; if (delta < 0) { LstScrollList(listP, winUp, -delta); } else if (delta > 0) { LstScrollList(listP, winDown, delta); } } else { SndPlaySystemSound(sndError); } } } } else if (event.eType == appStopEvent) { EvtAddEventToQueue (&event); done = true; break; } // If we didn't handle the event, give the form code a crack at it. // This simulates the "normal" method of installing an event handler // for a form, which gets called, and then if it returns false, the // FrmHandleEvent routine gets called. if (!handled) { FrmHandleEvent(dialog, &event); } // If something changed, and we need to update our time display, // do it now. if (adjustTimes) { adjustTimes = false; newTime = currentTime; TimAdjust(&newTime, (Int32)(newTimeZone - oldTimeZone) * minutesInSeconds); PrvSetTimeField(dialog, TimeZoneDialogNewTimeField, newTimeHandle, &newTime, true); } } // end while true if (showTimes) { FldSetTextHandle(FrmGetObjectPtr (dialog, FrmGetObjectIndex (dialog, TimeZoneDialogCurrentTimeField)), NULL); FldSetTextHandle(FrmGetObjectPtr (dialog, FrmGetObjectIndex (dialog, TimeZoneDialogNewTimeField)), NULL); MemHandleFree(currentTimeHandle); MemHandleFree(newTimeHandle); } FrmEraseForm (dialog); FrmDeleteForm (dialog); FrmSetActiveForm(originalForm); PrvDeleteTimeZoneArray(tzArrayP, tzNamesH); return confirmed; } // SelectTimeZone
/* Event handler for the main form */ Boolean FormHandleEvent ( EventType* event ) { Boolean handled; handled = false; switch ( event->eType ) { case ctlSelectEvent: switch ( event->data.ctlEnter.controlID ) { case frmPrefsButton: if ( buttonList[ PREF ].status == VALID && FrmAlert( confirmPrefs ) == 0 ) HandleButton( &buttonList[ PREF ] ); handled = true; break; case frmTempButton: if ( buttonList[ TEMP ].status == VALID && FrmAlert( confirmTemp ) == 0 ) HandleButton( &buttonList[ TEMP ] ); handled = true; break; case frmDocListButton: if ( buttonList[ DOCLIST ].status == VALID && FrmAlert( confirmDocList ) == 0 ) HandleButton( &buttonList[ DOCLIST ] ); handled = true; break; case frmFontCacheButton: if ( buttonList[ FONTCACHE ].status == VALID && FrmAlert( confirmFontCache ) == 0 ) HandleButton( &buttonList[ FONTCACHE ] ); handled = true; break; case frmDone: { EventType stopEvent; stopEvent.eType = appStopEvent; EvtAddEventToQueue( &stopEvent ); handled = true; break; } case frmWhatIsThis: FrmHelp( strWhatIsThis ); handled = true; break; default: break; } break; case menuEvent: switch ( event->data.menu.itemID ) { case menuHelpWhatIsThis: FrmHelp( strWhatIsThis ); handled = true; break; case menuHelpAbout: { FormType* form; form = FrmInitForm( frmAbout ); FrmDoDialog( form ); FrmDeleteForm( form ); handled = true; break; } } break; case frmOpenEvent: FormInit(); handled = true; break; case frmCloseEvent: FreeMemory(); handled = false; break; default: handled = false; break; } return handled; }