static void DrawList() { FormPtr form = FrmGetActiveForm(); if (FormIsNot(form, FormGroupManagement)) return; ListPtr list = (ListPtr) GetObjectPtr(form, ListGroups); LstSetListChoices(list, NULL, g_PhoneGroups.size()); LstSetDrawFunction(list, ListDrawDataFunc); LstDrawList(list); }
static void DrawList() { FormPtr form = FrmGetActiveForm(); if (FormIsNot(form, FormReply)) return; ListPtr list = (ListPtr) GetObjectPtr(form, ListGroups); LstSetListChoices(list, NULL, g_PhoneGroups.size() + 1); UInt16 maxVisible = 8; if (g_PhoneGroups.size() < maxVisible - 1) maxVisible = g_PhoneGroups.size() + 1; LstSetHeight(list, maxVisible); LstSetDrawFunction(list, ListDrawDataFunc); LstDrawList(list); }
static Boolean ResidentBrowseFormWinEnter(AppContext* appContext, FormType* form, EventType* event) { struct _WinEnterEventType* winEnter=(struct _WinEnterEventType*)&event->data; if (winEnter->enterWindow==(void*)form) // this means we're entering this window for the first time and we have to do initial list drawing { FieldType* field=NULL; ListType* list=NULL; UInt16 index=FrmGetObjectIndex(form, fieldWord); Assert(index!=frmInvalidObjectId); field=(FieldType*)FrmGetObjectPtr(form, index); index=FrmGetObjectIndex(form, listMatching); Assert(index!=frmInvalidObjectId); list=(ListType*)FrmGetObjectPtr(form, index); appContext->prevSelectedWord = 0xffffffff; LstSetListChoicesEx(list, NULL, dictGetWordsCount(GetCurrentFile(appContext))); LstSetDrawFunction(list, ListDrawFunc); appContext->prevTopItem = 0; Assert(appContext->selectedWord < appContext->wordsCount); if (*appContext->lastWord) { appContext->selectedWord = 0; FldInsert(field, appContext->lastWord, StrLen(appContext->lastWord)); FldSendChangeNotification(field); } else { if (-1==appContext->currentWord) appContext->selectedWord=0; else appContext->selectedWord=appContext->currentWord; LstSetSelectionEx(appContext, list, appContext->selectedWord); } index=FrmGetObjectIndex(form, fieldWord); Assert(index!=frmInvalidObjectId); FrmSetFocus(form, index); FrmUpdateForm(formResidentBrowse, frmRedrawUpdateCode); } return false; }
/* ** Popup the transfer details list. */ static void DoXferList(void) { const Int16 num_plugs = PlugIndex(NULL, true); if (!d.xfer.pluglistH || !num_plugs) { FrmAlert(NoPluginInstalled); } else { RectangleType rect; Int16 list_selection = -1; FormType* frm = FrmGetActiveForm(); ListPtr list = GetObjectPointer(frm, XferList); /* Set up plugin list control */ LstSetDrawFunction(list, XferListDrawFunc); LstSetListChoices(list, NULL, num_plugs); LstSetHeight(list, Min(num_plugs, 10)); FrmGetObjectBounds(frm, FrmGetObjectIndex(frm, XferList), &rect); rect.topLeft.x = 16; rect.topLeft.y = 144 - rect.extent.y; rect.extent.x = d.xfer.plug_menu_width; FrmSetObjectBounds(frm, FrmGetObjectIndex(frm, XferList), &rect); /* Pop up the list */ LstSetSelection(list, GetCurrentXferAppListIndex()); list_selection = LstPopupList(list); if (list_selection != -1) { SysDBListItemType* pluglistP = MemHandleLock(d.xfer.pluglistH); /* Store the current plugin */ p.xfer_current_plug = pluglistP[PlugIndex(list_selection, false)].creator; /* Clean up */ MemHandleUnlock(d.xfer.pluglistH); } } }
Boolean BookmarksFormHandleEvent(EventType * event) { Boolean handled = false; FormType * frm; ListType * bkmList, * sortTypeList; char * listTxt; UInt16 bookmarksCount; AppContext* appContext = GetAppContext(); frm = FrmGetActiveForm(); switch (event->eType) { case frmOpenEvent: OpenBookmarksDB(appContext, appContext->prefs.bookmarksSortType); bkmList = (ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listBookmarks)); bookmarksCount = BookmarksWordCount(appContext); Assert( 0 != bookmarksCount ); LstSetDrawFunction(bkmList, BookmarksListDrawFunc); LstSetListChoices(bkmList, NULL, bookmarksCount); sortTypeList = (ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listSortBy)); // list position matches enums for simplicity LstSetSelection(sortTypeList, (Int16)appContext->prefs.bookmarksSortType); listTxt = LstGetSelectionText(sortTypeList, appContext->prefs.bookmarksSortType); CtlSetLabel((ControlType *)FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,popupSortBy)), listTxt); FrmDrawForm(frm); handled = true; break; case winDisplayChangedEvent: handled= BookmarksFormDisplayChanged(appContext, frm); break; case ctlSelectEvent: switch (event->data.ctlSelect.controlID) { case buttonCancel: CloseBookmarksDB(appContext); FrmReturnToForm(0); handled = true; break; case popupSortBy: // do nothing break; default: Assert(false); break; } break; case popSelectEvent: switch (event->data.popSelect.listID) { case listSortBy: Assert( appContext->currBookmarkDbType == appContext->prefs.bookmarksSortType ); if ((BookmarkSortType) event->data.popSelect.selection != appContext->prefs.bookmarksSortType) { // we changed sorting type sortTypeList = (ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listSortBy)); listTxt = LstGetSelectionText(sortTypeList, event->data.popSelect.selection); CtlSetLabel((ControlType *)FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,popupSortBy)), listTxt); // list position matches enums for simplicity OpenBookmarksDB(appContext, (BookmarkSortType) event->data.popSelect.selection); appContext->prefs.bookmarksSortType = (BookmarkSortType) event->data.popSelect.selection; #ifdef DEBUG // word count shouldn't change bookmarksCount = BookmarksWordCount(appContext); bkmList = (ListType *) FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, listBookmarks)); Assert( LstGetNumberOfItems(bkmList) == bookmarksCount ); #endif FrmDrawForm(frm); } handled = true; break; default: Assert(false); break; } break; case lstSelectEvent: { MemHandle recHandle; char * word; recHandle = DmQueryRecord(appContext->bookmarksDb, event->data.lstSelect.selection); Assert( recHandle ); // no reason it shouldn't work if (recHandle) { word = (char*)MemHandleLock(recHandle); Assert(word); #ifndef I_NOAH appContext->currentWord = dictGetFirstMatching(GetCurrentFile(appContext), word); MemHandleUnlock(recHandle); SendEvtWithType(evtNewWordSelected); #else FrmReturnToForm(0); StartWordLookup(appContext, word); MemHandleUnlock(recHandle); #endif } CloseBookmarksDB(appContext); #ifndef I_NOAH FrmReturnToForm(0); #endif handled = true; } default: break; } return handled; }
/* Populate list with bookmarks, return number of bookmarks in list */ static UInt16 InitBookmarkList ( ListType* list /* pointer to list */ ) { UInt16 entries; UInt16 extEntries; UInt16 extraListItems; UInt16 i; MemHandle handle; Char** nameList; UInt8* bookmarkPtr; handle = NULL; nameList = NULL; bookmarkPtr = NULL; /* default is "Add bookmark" and "View bookmarks" */ entries = 0; extraListItems = 2; extEntries = CountExtBookmarks(); handle = ReturnMetaHandle( INTERNAL_BOOKMARKS_ID, NO_PARAGRAPHS ); if ( handle != NULL ) { if ( isPopupList ) extraListItems = 2; else extraListItems = 0; bookmarkPtr = MemHandleLock( handle ); entries += GET_ENTRIES( bookmarkPtr ); bookmarkPtr += BOOKMARK_HEADER_LEN; } else { if ( ! isPopupList ) { extraListItems = 0; if ( extEntries == 0 ) { LstSetListChoices( list, nameList, NO_BOOKMARKS ); LstSetDrawFunction( list, DrawListItem ); return NO_BOOKMARKS; } } } entries += extraListItems + extEntries; /* Allocate arrays for name list */ nameListHandle = MemHandleNew( entries * sizeof( *nameList ) ); if ( nameListHandle == NULL ) { if ( extraListItems < entries - extEntries ) MemHandleUnlock( handle ); return NO_BOOKMARKS; } nameList = MemHandleLock( nameListHandle ); if ( isPopupList ) { SysCopyStringResource( addBookmark, strMainAddBookmark ); nameList[ ADD_BOOKMARK ] = addBookmark; SysCopyStringResource( editBookmark, strMainViewBookmark ); nameList[ EDIT_BOOKMARK ] = editBookmark; } if ( 0 < extEntries ) InitExtBookmarkList( nameList, extraListItems ); if ( handle != NULL ) { for ( i = extraListItems + extEntries; i < entries; i++ ) { nameList[ i ] = bookmarkPtr; bookmarkPtr += StrLen( bookmarkPtr ) + 1; } } LstSetListChoices( list, nameList, entries ); LstSetDrawFunction( list, DrawListItem ); if ( isPopupList ) LstSetHeight( list, entries ); if ( extraListItems < entries - extEntries ) MemHandleUnlock( handle ); return entries; }
/* ** TrackXferDone */ static void TrackXferDone(DynamicButtonType* btn) { RectangleType bounds[5], frame, popFrame, popShadowFrame; Boolean penDown, on_button; Int16 x, y, clicked_on = 0; Int16 state = 1; Int16 i = 0; WinHandle offscreenH = NULL; FormType* frm = FrmGetActiveForm(); const UInt16 listIdx = FrmGetObjectIndex(frm, XferDoneList); ListType* list = FrmGetObjectPtr(frm, listIdx); UInt16 width = 0, choices = 0; Err err = errNone; Char str[48]; Int16 n = 0; /* Save the old drawing context */ WinPushDrawState(); /* This should match the XferDoneButton bounds */ FrmGetObjectBounds(frm, FrmGetObjectIndex(frm, btn->id), &bounds[0]); /* Invert the done button */ SelectAndDrawButton(btn, true); SndPlaySystemSound(sndClick); /* Set the status of each menu pick */ for (; i < 4; i++) d.xfer.status[i] = 0x00; if (xferGotoIsAlways) d.xfer.status[0] = TRACKXFERDONE_ALWAYS; else if (xferGotoIsNever) d.xfer.status[0] = TRACKXFERDONE_NEVER; else if (p.flags&PFLAGS_XFER_GOTO) d.xfer.status[0] = TRACKXFERDONE_CHECKED; if (xferCompleteIsAlways) d.xfer.status[1] = TRACKXFERDONE_ALWAYS; else if (xferCompleteIsNever) d.xfer.status[1] = TRACKXFERDONE_NEVER; else if (d.xfer.complete) d.xfer.status[1] = TRACKXFERDONE_CHECKED; if (!d.linker_available) d.xfer.status[2] = TRACKXFERDONE_NEVER; else if (p.flags&PFLAGS_XFER_BACKLINK) d.xfer.status[2] = TRACKXFERDONE_CHECKED; if (p.flags&PFLAGS_XFER_DELETE) d.xfer.status[3] = TRACKXFERDONE_CHECKED; for (i = 0; i < 4; ++i) { if (!(d.xfer.status[i] & TRACKXFERDONE_NEVER)) { d.xfer.choice_map[choices] = i; ++choices; /* calculate list width */ SysCopyStringResource(str, XferMenuOptionsStrings + i); n = FntCharsWidth(str, StrLen(str)); width = Max(width, n); } } LstSetDrawFunction(list, XferDoneListDrawFunc); LstSetListChoices(list, 0, choices); LstSetHeight(list, Min(choices, 10)); FrmGetObjectBounds(frm, listIdx, &frame); frame.topLeft.y = 144 - frame.extent.y - 1; /* -1 to compensate for white border */ frame.extent.x = width + 15 + 6; FrmSetObjectBounds(frm, listIdx, &frame); WinGetFramesRectangle(popupFrame, &frame, &popFrame); WinGetFramesRectangle(rectangleFrame, &popFrame, &popShadowFrame); for (i = 0; i < choices; ++i) RctSetRectangle(&bounds[i+1], frame.topLeft.x, frame.topLeft.y + 10 * i, frame.extent.x, 10); /* Save the bits of the whole menu */ offscreenH = WinSaveBits(&popShadowFrame, &err); if (err) abort(); /* None selected */ LstSetSelection(list, -1); FrmShowObject(frm, listIdx); WinEraseRectangle(&popShadowFrame, 0); LstDrawList(list); WinEraseRectangleFrame(rectangleFrame, &frame); WinDrawRectangleFrame(popupFrame, &frame); do { EvtGetPen(&x, &y, &penDown); if (!state || !RctPtInRectangle(x, y, &bounds[state-1])) { on_button = false; for (i = 1; i <= choices + 1; i++) { if ((state != i) && RctPtInRectangle(x, y, &bounds[i-1])) { /* Invert the new state */ LstSetSelection(list, i - 2); LstDrawList(list); WinEraseRectangleFrame(rectangleFrame, &frame); WinDrawRectangleFrame(popupFrame, &frame); SelectAndDrawButton(btn, i == 1); state = i; on_button = true; } } if (state && !on_button) { /* Moved off the current button */ LstSetSelection(list, -1); LstDrawList(list); WinEraseRectangleFrame(rectangleFrame, &frame); WinDrawRectangleFrame(popupFrame, &frame); if (state == 1) SelectAndDrawButton(btn, false); state = 0; } } } while (penDown); FrmHideObject(frm, listIdx); LstEraseList(list); /* Restore the framed rect */ WinRestoreBits(offscreenH, popShadowFrame.topLeft.x, popShadowFrame.topLeft.y); /* Unselect the button */ SelectAndDrawButton(btn, false); /* Finish up if we just tapped the button */ if (RctPtInRectangle(x, y, &bounds[0])) { FinishXferMode(); /* Restore the old draw state */ WinPopDrawState(); return; } /* Change the setting for goto or delete */ for (i = 1; i <= choices; i++) { if (RctPtInRectangle(x, y, &bounds[i])) { clicked_on = i; break; } } if (clicked_on) clicked_on = d.xfer.choice_map[clicked_on-1] + 1; switch (clicked_on) { case 1: /* Goto */ if (d.xfer.status[0] & TRACKXFERDONE_CHECKED) p.flags &= ~PFLAGS_XFER_GOTO; else if (!d.xfer.status[0]) p.flags |= PFLAGS_XFER_GOTO; break; case 2: /* Complete */ if (d.xfer.status[1] & TRACKXFERDONE_CHECKED) d.xfer.complete = false; else if (!d.xfer.status[1]) d.xfer.complete = true; break; case 3: /* BackLink */ if (d.xfer.status[2] & TRACKXFERDONE_CHECKED) p.flags &= ~PFLAGS_XFER_BACKLINK; else if (!d.xfer.status[2]) { p.flags |= PFLAGS_XFER_BACKLINK; p.flags &= ~PFLAGS_XFER_DELETE; /* No delete if backlink */ } break; case 4: /* Delete */ if (d.xfer.status[3] & TRACKXFERDONE_CHECKED) p.flags &= ~PFLAGS_XFER_DELETE; else if (!d.xfer.status[3]) { p.flags |= PFLAGS_XFER_DELETE; p.flags &= ~PFLAGS_XFER_BACKLINK; /* No backlink if delete */ } break; } /* Click and redraw the button */ if (clicked_on) { DrawXferDoneButton(btn); DynBtnDraw(btn); if (d.xfer.status[clicked_on-1] & TRACKXFERDONE_ALWAYS) SndPlaySystemSound(sndWarning); else SndPlaySystemSound(sndClick); } /* Restore the old draw state */ WinPopDrawState(); }
/* Populate list with bookmarks, return number of bookmarks in list */ static UInt16 InitBookmarkList ( ListType* list /* pointer to list */ ) { UInt16 recordNum; UInt16 numRecords; UInt16 extEntries; UInt16 bookmarks; UInt16 extraListItems; UInt16 index; UInt16 i; if ( isPopupList ) { #ifdef SUPPORT_ANNOTATION extraListItems = 3; #else extraListItems = 2; #endif } else { extraListItems = 0; } ReleaseBookmarkList(); extEntries = CountExtBookmarks(); bookmarks = CountBookmarks(); numRecords = GetNumberOfAnnotations(); numEntries = extraListItems + extEntries + bookmarks; if ( numEntries == 0 ) { LstSetListChoices( list, nameList, NO_BOOKMARKS ); LstSetDrawFunction( list, DrawListItem ); return NO_BOOKMARKS; } bookmarkList = SafeMemPtrNew( numEntries * sizeof( BookmarkListEntry* ) ); for ( i = 0 ; i < numEntries ; i++ ) { bookmarkList[ i ] = SafeMemPtrNew( sizeof( BookmarkListEntry ) ); MemSet( bookmarkList[ i ], sizeof( BookmarkListEntry ), 0 ); } /* Allocate arrays for name list */ nameList = SafeMemPtrNew( numEntries * sizeof( Char* ) ); if ( isPopupList ) { SysCopyStringResource( addBookmark, strMainAddBookmark ); nameList[ ADD_BOOKMARK ] = addBookmark; bookmarkList[ ADD_BOOKMARK ]->kind = BOOKMARK_ADD_BOOKMARK; #ifdef SUPPORT_ANNOTATION SysCopyStringResource( addAnnotation, strMainAddAnnotation ); nameList[ ADD_ANNOTATION ] = addAnnotation; bookmarkList[ ADD_ANNOTATION ]->kind = BOOKMARK_ADD_ANNOTATION; #endif SysCopyStringResource( editBookmark, strMainViewBookmark ); nameList[ EDIT_BOOKMARK ] = editBookmark; bookmarkList[ EDIT_BOOKMARK ]->kind = BOOKMARK_EDIT_BOOKMARK; } if ( 0 < extEntries ) { InitExtBookmarkList( nameList, extraListItems ); for ( i = extraListItems ; i < extraListItems + extEntries ; i++ ) { bookmarkList[ i ]->kind = BOOKMARK_EXT_BOOKMARK; bookmarkList[ i ]->recordNum = i - extraListItems; } } index = extraListItems + extEntries; for ( recordNum = 0 ; recordNum < numRecords && index < numEntries ; recordNum++ ) { MemHandle h; h = GetAnnotationByRecordNum( recordNum ); if ( h != NULL ) { AnnotationEntry* entryP; entryP = MemHandleLock( h ); if ( 1 < entryP->dataLength && ! ( ! ( entryP->flags & ANNOTATION_BOOKMARK ) && Prefs()->noAnnotationsInBookmarkList ) ) { UInt32 labelSize; labelSize = entryP->dataLength - 1; if ( MAX_BOOKMARK_ENTRY_LENGTH < labelSize ) labelSize = MAX_BOOKMARK_ENTRY_LENGTH; bookmarkList[ index ]->text = MemPtrNew( labelSize + 1 ); if ( bookmarkList[ index ]->text != NULL ) { bookmarkList[ index ]->kind = ( entryP->flags & ANNOTATION_BOOKMARK ) ? BOOKMARK_BOOKMARK : BOOKMARK_ANNOTATION; bookmarkList[ index ]->recordNum = recordNum; StrNCopy( bookmarkList[ index ]->text, ( Char* )entryP + entryP->dataOffset, labelSize + 1 ); bookmarkList[ index ]->text[ labelSize ] = 0; nameList[ index ] = bookmarkList[ index ]->text; index++; } } MemHandleUnlock( h ); } } numEntries = index; LstSetListChoices( list, nameList, numEntries ); LstSetDrawFunction( list, DrawListItem ); if ( isPopupList ) LstSetHeight( list, numEntries ); return numEntries; }
/*********************************************************************** * * 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