PALM开发教程-第八章 表和滚动条 |
| 作者:palmheart 来源:palmheart.net 发布时间:2005-12-21 3:35:05 |
|
form = FrmGetActiveForm(); // CH.7 Parse events switch( event->eType ) { // CH.7 Form open event case frmOpenEvent: { // CH.7 Draw the form FrmDrawForm( form ); // CH.8 Populate and draw the table drawTable(); } break; // CH.7 Respond to a list selection case tblSelectEvent: { // CH.7 Set the database cursor to the selected contact cursor += event->data.tblSelect.row; // CH.7 Go to contact details FrmGotoForm( ContactDetailForm ); } break; // CH.7 Respond to a menu event case menuEvent: return( menuEventHandler( event ) ); // CH.7 Respond to the popup trigger case popSelectEvent: { // CH.7 If there is no change, we're done if( sortBy == event->data.popSelect.selection ) return( true ); // CH.7 Modify sort order variable sortBy = event->data.popSelect.selection; // CH.7 Sort the contact database by the new criteria DmQuickSort( contactsDB, (DmComparF*)sortFunc, sortBy ); // CH.8 Rebuild the table drawTable(); } break; // CH.8 Respond to arrows case ctlRepeatEvent: { switch( event->data.ctlRepeat.controlID ) { // CH.8 Up arrow case ContactListRecordUpRepeating: if( cursor > 0 ) cursor--; break; // CH.8 Down arrow case ContactListRecordDownRepeating: if( (numRecords > TABLE_NUM_ROWS) && (cursor < numRecords - TABLE_NUM_ROWS) ) cursor++; break; } // CH.8 Now refresh the table drawTable(); } return( true ); // CH.8 Respond to up and down arrow hard keys case keyDownEvent: { switch( event->data.keyDown.chr ) { // CH.8 Up arrow hard key case pageUpChr: if( cursor > TABLE_NUM_ROWS - 1 ) cursor -= TABLE_NUM_ROWS - 1; else cursor = 0; break; // CH.8 Down arrow hard key case pageDownChr: if( (numRecords > 2 * TABLE_NUM_ROWS - 1) && (cursor < numRecords - 2 * TABLE_NUM_ROWS - 1) ) cursor += TABLE_NUM_ROWS - 1; else cursor = numRecords - TABLE_NUM_ROWS; break; } // CH.8 Now refresh the table drawTable(); } break; // CH.8 Respond to scrollbar events case sclRepeatEvent: cursor = event->data.sclExit.newValue; drawTable(); break; } // CH.7 End of the event switch statement // CH.7 We're done return( false ); } // CH.3 Handle menu events Boolean menuEventHandler( EventPtr event ) { FormPtr form; // CH.3 A pointer to our form structure Word index; // CH.3 A general purpose control index FieldPtr field; // CH.3 Used for manipulating fields // CH.3 Get our form pointer form = FrmGetActiveForm(); // CH.3 Erase the menu status from the display MenuEraseStatus( NULL ); // CH.4 Handle options menu if( event->data.menu.itemID == OptionsAboutContacts ) { // CH.4 Pop up the About form as a Dialog FrmPopupForm( AboutForm ); return( true ); } // CH.3 Handle graffiti help if( event->data.menu.itemID == EditGraffitiHelp ) { // CH.3 Pop up the graffiti reference based on // the graffiti state SysGraffitiReferenceDialog( referenceDefault ); return( true ); } // CH.3 Get the index of our field index = FrmGetFocus( form ); // CH.3 If there is no field selected, we're done if( index == noFocus ) return( false ); // CH.3 Get the pointer of our field field = FrmGetObjectPtr( form, index ); // CH.3 Do the edit command switch( event->data.menu.itemID ) { // CH.3 Undo case EditUnd FldUndo( field ); break; // CH.3 Cut case EditCut: FldCut( field ); break; // CH.3 Copy case EditCopy: FldCopy( field ); break; // CH.3 Paste case EditPaste: FldPaste( field ); break; // CH.3 Select All case EditSelectAll: { // CH.3 Get the length of the string in the field Word length = FldGetTextLength( field ); // CH.3 Sound an error if appropriate if( length == 0 ) { SndPlaySystemSound( sndError ); return( false ); } // CH.3 Select the whole string FldSetSelection( field, 0, length ); } break; // CH.3 Bring up the keyboard tool case EditKeyboard: SysKeyboardDialogV10(); break; } // CH.3 We're done return( true ); } // CH.5 This function creates and initializes a new record static void newRecord( void ) { VoidPtr precord; // CH.5 Pointer to the record // CH.7 Create the database record and get a handle to it if( (hrecord = DmNewRecord( contactsDB, &cursor, DB_RECORD_SIZE )) == NULL ) errorExit( MemoryErrorAlert ); // CH.5 Lock down the record to modify it precord = MemHandleLock( hrecord ); // CH.5 Clear the record DmSet( precord, 0, DB_RECORD_SIZE, 0 ); // CH.6 Initialize the date and time MemSet( &dateTime, sizeof( dateTime ), 0 ); dateTime.year = NO_DATE; dateTime.hour = NO_TIME; DmWrite( precord, DB_DATE_TIME_START, &dateTime, sizeof( DateTimeType ) ); // CH.5 Unlock the record MemHandleUnlock( hrecord ); // CH.5 Clear the busy bit and set the dirty bit DmReleaseRecord( contactsDB, cursor, true ); // CH.5 Increment the total record count numRecords++; // CH.5 Set the dirty bit isDirty = true; // CH.5 We're done return; } // CH.5 A time saver: Gets object pointers based on their ID static VoidPtr getObject( FormPtr form, Word objectID ) { Word index; // CH.5 The object index // CH.5 Get the index index = FrmGetObjectIndex( |
| [] [返回上一页] [打 印] |
|
文章评论 |
