📄 quiklist.c
字号:
( void){ Boolean catEdited = false; UInt16 newCatNum = gCurCatNum; char curCatName [ dmCategoryLength ]; CategoryGetName ( gDBRef, gCurCatNum, curCatName );// Let the user select a new category or edit the category names.// SIDE EFFECT - CategorySelect changes curCatName if the// current category changes. catEdited = CategorySelect ( gDBRef, FrmGetActiveForm (), MainCategoryPopTrigger, MainCategoriesList, true, &newCatNum, curCatName, 1, 0 ); // Check to see if the current category has changed in any way. if ( catEdited || ( newCatNum != gCurCatNum )) { // If so, reset the popup to show the new category name gCurCatNum = newCatNum; CategorySetTriggerLabel ( GetObjectPtr ( MainCategoryPopTrigger ), curCatName ); // We also need to redraw the list gTopItem = 0; gListSize = ( Int16 ) DmNumRecordsInCategory ( gDBRef, gCurCatNum ); MainFormDrawList (); }}/*********************************************************************** * FUNCTION: MainFormHandleROCategory * * DESCRIPTION: Handle a category popup event for a read-only database. * * RETURNED: nothing ***********************************************************************/static void MainFormHandleROCategory( void){ char curCatName [ dmCategoryLength ]; UInt16 newCatNum = gCurCatNum; ListPtr listP = GetObjectPtr ( MainCategoriesList ); // Create a temporary popup using the category data from the database CategoryCreateList ( gDBRef, listP, gCurCatNum, true, true, 0, 0, true ); if ( listP ) { // Display the popup list and let the user select a new category newCatNum = ( UInt16 ) LstPopupList ( listP ); if ( newCatNum >= 0 ) { // Map "All" back into it's internal representation if ( newCatNum == 0 ) newCatNum = dmAllCategories; // Check to see if the current category has changed in any way. if ( newCatNum != gCurCatNum ) { gCurCatNum = newCatNum; // If so, reset the popup to show the new category name. Have to// kludge "All" and "Unfiled" because we're using a normal popup, // not a category popup that automatically handles both cases. if ( gCurCatNum < LstGetNumberOfItems ( listP ) - 1 ) CategoryGetName ( gDBRef, gCurCatNum, curCatName ); else if ( gCurCatNum == dmAllCategories ) StrCopy ( curCatName, "All" ); else StrCopy ( curCatName, "Unfiled" ); CategorySetTriggerLabel ( GetObjectPtr ( MainCategoryPopTrigger ), curCatName ); // Redraw the list to show the new record set gTopItem = 0; gListSize = ( Int16 ) DmNumRecordsInCategory ( gDBRef, gCurCatNum ); MainFormDrawList (); } } } CategoryFreeList ( gDBRef, listP, true, 0 );}#pragma mark ----------------/*********************************************************************** * FUNCTION: MainFormInit * * DESCRIPTION: This routine initializes the Main form. It should be used to * execute code that must be done _before_ the form is * drawn using FrmDrawForm. * * RETURNED: nothing ***********************************************************************/static void MainFormInit( FormPtr frmP // ( in ) Pointer to the main form){ if ( frmP != NULL ) { RctSetRectangle ( &gListBounds, TOP_LEFT_X, TOP_LEFT_Y, EXTENT_X, EXTENT_Y ); }}/*********************************************************************** * FUNCTION: MainFormDraw * * DESCRIPTION: This routine draws the non-form contents of the Main form. * * RETURNED: nothing ***********************************************************************/static void MainFormDraw( FormPtr frmP // ( in ) Pointer to the main form.){ char curCatName [ dmCategoryLength ]; if ( frmP != NULL ) { // Draw the current list WinDrawRectangleFrame ( simpleFrame, &gListBounds ); MainFormDrawList (); // Draw the current category popup CategoryGetName ( gDBRef, gCurCatNum, curCatName ); CategorySetTriggerLabel ( GetObjectPtr ( MainCategoryPopTrigger ), curCatName ); }}/*********************************************************************** * FUNCTION: MainFormDone * * DESCRIPTION: This routine cleans up after the main form. * * RETURNED: nothing ***********************************************************************/static void MainFormDone( FormPtr frmP // ( in ) Pointer to the MainForm form){ if ( frmP != NULL ) { FrmEraseForm ( frmP ); FrmDeleteForm ( frmP ); }}/*********************************************************************** * FUNCTION: MainFormDoMenuCommand * * DESCRIPTION: This routine handles menu commands. * * RETURNED: nothing ***********************************************************************/static Boolean MainFormDoMenuCommand( UInt16 command // ( in ) The ID of menu command to do){ Boolean handled = false; FormPtr frmP; switch ( command ) { case MainOptionsAboutQuikList: MenuEraseStatus ( 0 ); frmP = FrmInitForm ( AboutForm ); FrmDoDialog ( frmP ); FrmDeleteForm ( frmP ); handled = true; break; } return handled;}/*********************************************************************** * FUNCTION: MainFormHandleEvent * * DESCRIPTION: This routine is the event handler for MainForm. * * RETURNED: true if the event is handled. ***********************************************************************/static Boolean MainFormHandleEvent( EventPtr eventP // ( in ) Pointer to the event to handle){ Boolean handled = false; FormPtr frmP = FrmGetActiveForm (); if ( frmP != NULL ) { switch ( eventP->eType ) {// Form events case frmOpenEvent: MainFormInit ( frmP ); // ***** WARNING - falls thru to next case ***** case frmUpdateEvent: FrmDrawForm ( frmP ); MainFormDraw( frmP ); handled = true; break; case frmCloseEvent: MainFormDone ( frmP ); handled = true; break; // Menu events case menuEvent: handled = MainFormDoMenuCommand ( eventP->data.menu.itemID ); break; // Control events case ctlSelectEvent: if ( eventP->data.ctlEnter.controlID == MainCategoryPopTrigger ) { if ( CheckDatabaseMode ( gDBRef , dmModeReadOnly+dmModeShowSecret)) MainFormHandleROCategory (); else MainFormHandleRWCategory (); handled = true; } break;// Keystrokes case keyDownEvent: handled = MainFormProcessKeystroke ( ( UInt8 ) eventP->data.keyDown.chr, false ); break; } } return handled;}#pragma mark ----------------/*********************************************************************** * FUNCTION: AppHandleEvent * * DESCRIPTION: Loads a form's resources and set its event handler. * * RETURNED: true if the event is handled. ***********************************************************************/static Boolean AppHandleEvent( EventPtr eventP // ( in ) Pointer to the event to handle){ Boolean handled = false; if ( eventP->eType == frmLoadEvent ) { // Form load event--initialize the form and make it the active form. UInt16 formId = eventP->data.frmLoad.formID; FormPtr frmP = FrmInitForm ( formId ); FrmSetActiveForm ( frmP );// Set the event handler for the form. switch ( formId ) { case MainForm: FrmSetEventHandler ( frmP, MainFormHandleEvent ); handled = true; break;// Insert other cases as needed for other forms. } handled = true; } return handled;}/*********************************************************************** * FUNCTION: AppEventLoop * * DESCRIPTION: The main event loop for the application. * * RETURNED: nothing ***********************************************************************/static void AppEventLoop( void){ UInt16 error; EventType event; do { // Get the next event EvtGetEvent ( &event, gEventTimeout );// Check the standard default handlers if (! SysHandleEvent ( &event)) if (! MenuHandleEvent ( 0, &event, &error )) if (! AppHandleEvent ( &event )) // Nobody wanted the event. Check for a nil event to turn off Graffiti lookup timing if ( event.eType == nilEvent && gNilEventCnt > 0 && FrmGetActiveFormID () == MainForm) { StopGrafftiLookup ( ); }// None of the above, take the default handler FrmDispatchEvent ( &event ); } while ( event.eType != appStopEvent );}/*********************************************************************** * FUNCTION: AppStart * * DESCRIPTION: Do whatever is necessary to get started, like read the app preferences. * * RETURNED: Err value or 0 if nothing went wrong ***********************************************************************/ static Err AppStart // ( out ) zero or an error code( void){ Err error; error = OpenDatabase ( APP_FILE_TYPE, APP_FILE_CREATOR, dmModeReadOnly+dmModeShowSecret, &gDBRef ); if ( ! error ) gListSize = ( Int16 ) DmNumRecords ( gDBRef ); return ( error );}/*********************************************************************** * FUNCTION: AppStop * * DESCRIPTION: Do whatever you need to do, like save the preferences. * * RETURNED: nothing ***********************************************************************/static void AppStop( void){ DmCloseDatabase ( gDBRef ); FrmCloseAllForms ();}/*********************************************************************** * FUNCTION: PilotMain * * DESCRIPTION: The application main entry point. * * RETURNED: 0 if launch & execution are successful, non-zero otherwise. ***********************************************************************/UInt32 PilotMain( UInt16 cmd, // ( in ) The launch code MemPtr /* cmdPBP*/, // ( in ) Pointer to the launch code structure UInt16 launchFlags // ( in ) Extra launch info){ Err error = 0;// Check the ROM version for compatibility. error = RomVersionCompatible ( MIN_ROM_VERSION, launchFlags); if ( error == 0 ){// ROM OK, check for the various launch codes as needed. switch (cmd) { case sysAppLaunchCmdNormalLaunch: error = AppStart (); if ( error == 0 ) { FrmGotoForm ( MainForm ); AppEventLoop (); AppStop (); } break; } } return ( UInt32 ) error;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -