PALM开发教程-第七章 列表框和排序 |
| 作者:palmheart 来源:palmheart.net 发布时间:2005-12-21 3:33:26 |
|
actListHandleEvent ); break; } FrmSetActiveForm( form ); } // CH.2 Handle form events FrmDispatchEvent( &event ); // CH.2 If it's a stop event, exit } while( event.eType != appStopEvent ); // CH.7 End the try block and do the catch block } ErrCatch( errorAlert ) { // CH.7 Display the appropriate alert FrmAlert( errorAlert ); } ErrEndCatch // CH.5 Close all open forms FrmCloseAllForms(); // CH.5 Close the database DmCloseDatabase( contactsDB ); // CH.2 We're done return( 0 ); } // CH.4 Our Contact Detail form handler function static Boolean contactDetailHandleEvent( EventPtr event ) { FormPtr form; // CH.3 A pointer to our form structure VoidPtr precord; // CH.6 Points to a database record // CH.3 Get our form pointer form = FrmGetActiveForm(); // CH.4 Parse events switch( event->eType ) { // CH.4 Form open event case frmOpenEvent: { // CH.2 Draw the form FrmDrawForm( form ); // CH.5 Draw the database fields setFields(); } break; // CH.5 Form close event case frmCloseEvent: { // CH.5 Store away any modified fields getFields(); } break; // CH.5 Parse the button events case ctlSelectEvent: { // CH.5 Store any field changes getFields(); switch( event->data.ctlSelect.controlID ) { // CH.5 First button case ContactDetailFirstButton: { // CH.5 Set the cursor to the first record if( cursor > 0 ) cursor = 0; } break; // CH.5 Previous button case ContactDetailPrevButton: { // CH.5 Move the cursor back one record if( cursor > 0 ) cursor--; } break; // CH.5 Next button case ContactDetailNextButton: { // CH.5 Move the cursor up one record if( cursor < (numRecords - 1) ) cursor++; } break; // CH.5 Last button case ContactDetailLastButton: { // CH.5 Move the cursor to the last record if( cursor < (numRecords - 1) ) cursor = numRecords - 1; } break; // CH.5 Delete button case ContactDetailDeleteButton: { // CH.5 Remove the record from the database DmRemoveRecord( contactsDB, cursor ); // CH.5 Decrease the number of records numRecords--; // CH.5 Place the cursor at the first record cursor = 0; // CH.5 If there are no records left, create one if( numRecords == 0 ) newRecord(); } break; // CH.5 New button case ContactDetailNewButton: { // CH.5 Create a new record newRecord(); } break; // CH.7 Done button case ContactDetailDoneButton: { // CH.7 Load the contact list FrmGotoForm( ContactListForm ); } break; // CH.6 Date selector trigger case ContactDetailDateSelTrigger: { // CH.6 Initialize the date if necessary if( dateTime.year == NO_DATE ) { DateTimeType currentDate; // CH.6 Get the current date TimSecondsToDateTime( TimGetSeconds(), ¤tDate ); // CH.6 Copy it dateTime.year = currentDate.year; dateTime.month = currentDate.month; dateTime.day = currentDate.day; } // CH.6 Pop up the system date selection form SelectDay( selectDayByDay, &(dateTime.month), &(dateTime.day), &(dateTime.year), "Enter Date" ); // CH.6 Get the record hrecord = DmQueryRecord( contactsDB, cursor ); // CH.6 Lock it down precord = MemHandleLock( hrecord ); // CH.6 Write the date time field DmWrite( precord, DB_DATE_TIME_START, &dateTime, sizeof( DateTimeType ) ); // CH.6 Unlock the record MemHandleUnlock( hrecord ); // CH.6 Mark the record dirty isDirty = true; } break; // CH.6 Time selector trigger case ContactDetailTimeSelTrigger: { // CH.6 Pop up our selection form FrmPopupForm( EnterTimeForm ); } break; } // CH.5 Sync the current record to the fields setFields(); } break; // CH.5 Respond to field tap case fldEnterEvent: isDirty = true; break; // CH.3 Parse menu events case menuEvent: return( menuEventHandler( event ) ); break; } // CH.2 We're done return( false ); } // CH.4 Our About form event handler function static Boolean aboutHandleEvent( EventPtr event ) { FormPtr form; // CH.4 A pointer to our form structure // CH.4 Get our form pointer form = FrmGetActiveForm(); // CH.4 Respond to the Open event if( event->eType == frmOpenEvent ) { // CH.4 Draw the form FrmDrawForm( form ); } // CH.4 Return to the calling form if( event->eType == ctlSelectEvent ) { FrmReturnToForm( 0 ); // CH.4 Always return true in this case return( true ); } // CH.4 We're done return( false ); } // CH.6 Our Enter Time form event handler function static Boolean enterTimeHandleEvent( EventPtr event ) { FormPtr form; // CH.6 A form structure pointer static DateTimeType oldTime; // CH.6 The original time // CH.6 Get our form pointer form = FrmGetActiveForm(); // CH.6 Switch on the event switch( event->eType ) { // CH.6 Initialize the form case frmOpenEvent: { // CH.6 Store the time value oldTime = dateTime; // CH.6 Draw it FrmDrawForm( form ); // CH.6 Set the time controls setTimeControls(); } break; // CH.6 If a button was repeated case ctlRepeatEvent: // CH.6 If a button was pushed case ctlSelectEvent: { Word buttonID; // CH.6 The ID |
| [] [返回上一页] [打 印] |
|
文章评论 |
