PALM开发教程-第九章 分类和查找 |
| 作者:palmheart 来源:palmheart.net 发布时间:2005-12-21 3:36:55 |
|
etObject( form, ContactListCategoryPopupPopTrigger ), catName ); // CH.8 The cursor starts at the beginning cursor = 0; // CH.9 Initialize the table indexes initIndexes(); // 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 = tableIndex[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 Cursor starts at zero cursor = 0; // CH.9 Initialize the table indexes initIndexes(); // 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: scrollIndexes( -1 ); break; // CH.8 Down arrow case ContactListRecordDownRepeating: scrollIndexes( 1 ); break; } // CH.8 Now refresh the table drawTable(); } break; // 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: scrollIndexes( -(TABLE_NUM_ROWS - 1) ); break; // CH.8 Down arrow hard key case pageDownChr: scrollIndexes( TABLE_NUM_ROWS - 1 ); break; } // CH.8 Now refresh the table drawTable(); } break; // CH.8 Respond to scrollbar events case sclExitEvent: { //CH.9 Find the record in our category cursor = findIndex( event->data.sclExit.newValue ); // CH.9 Initialize our index list initIndexes(); // CH.8 Draw the table drawTable(); } break; // CH.9 Catch a tap on the category trigger case ctlSelectEvent: { // CH.9 Palm OS will present the popup list for us. CategorySelect( contactsDB, form, ContactListCategoryPopupPopTrigger, ContactListCategoryListList, true, &listCat, catName, 1, 0 ); // CH.9 Cursor starts at zero cursor = 0; // CH.9 Initialize the indexes initIndexes(); // CH.9 Draw the table drawTable(); } // CH.9 Don't let the OS generate other events from this return( true ); } // 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 UInt recAttrs; // CH.9 The record's attributes // 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( DateT |
| [] [返回上一页] [打 印] |
|
文章评论 |
