static void SelectNextInList(Int16 step) { FormPtr frmP = FrmGetActiveForm(); if (FormIsNot(frmP, FormReply)) return; ListPtr list = (ListPtr) GetObjectPtr(frmP, ListGroups); Int16 sel = LstGetSelection(list); if (sel == noListSelection) return; sel += step; if (sel < 0) sel = 0; if (sel >= LstGetNumberOfItems(list)) sel = LstGetNumberOfItems(list) - 1; LstSetSelection(list, sel); }
static void ScrollBoundedList(const FormType* form, UInt16 listId, Int16 delta) { Assert(form); UInt16 index=FrmGetObjectIndex(form, listId); Assert(frmInvalidObjectId!=index); ListType* list=static_cast<ListType*>(FrmGetObjectPtr(form, index)); Assert(list); Int16 position=LstGetSelection(list); if (noListSelection==position) position=LstGetTopItem(list); position+=delta; if (position<0) position=0; else { UInt16 itemsCount=LstGetNumberOfItems(list); if (position>itemsCount) position=itemsCount-1; } LstSetSelection(list, position); }
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; }