⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pakadb.c

📁 CD_高级PALM编程
💻 C
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************** * FUNCTION:    	MainFormDoMenuCommand * * DESCRIPTION: 	This routine handles menu commands. * * RETURNED:    	nothing ***********************************************************************/ static Boolean MainFormDoMenuCommand(	UInt16 	command			// The ID of menu command to do){	Boolean handled = false;	FormPtr frmP;	switch ( command )	{		case MainOptionsAboutPakaDB:					MenuEraseStatus ( 0 );			frmP = FrmInitForm ( AboutForm );			FrmDoDialog ( frmP );			FrmDeleteForm ( frmP );			handled = true;			break;	}	return handled;}/*********************************************************************** * FUNCTION:    	MainFormHandleControl * * DESCRIPTION: 	This routine handles control events for the MainForm. * * RETURNED:    	true if the event is handled. ***********************************************************************/static Boolean MainFormHandleControl(		UInt16		controlID	// The ID  of the control hit.)		{	Boolean handled = false;	UInt16 recordCount;	DmOpenRef dbRef;	UInt16 big;		dbRef = DmOpenDatabase( 0, mainDatabaseIDList[mainDatabaseDisplayed], dmModeReadOnly);	recordCount = DmNumRecords( dbRef );	DmCloseDatabase( dbRef );		big = recordCount / 8;		switch( controlID )	{		case MainBackButton:			if ( mainDatabaseRecordDisplayed != 0 )			{				mainDatabaseRecordDisplayed--;			 	MainFormDrawRecordView( );			}			handled = true;			break;					case MainNextButton:			if ( mainDatabaseRecordDisplayed < recordCount-1 )			{				mainDatabaseRecordDisplayed++;			 	MainFormDrawRecordView( );			}			handled = true;			break;					case MainBackBigButton:			if ( mainDatabaseRecordDisplayed != 0 )			{				mainDatabaseRecordDisplayed -= big;				mainDatabaseRecordDisplayed = mainDatabaseRecordDisplayed < 0 ? 					0 : mainDatabaseRecordDisplayed;			 	MainFormDrawRecordView( );			}			handled = true;			break;							case MainNextBigButton:			if ( mainDatabaseRecordDisplayed < recordCount-1 )			{				mainDatabaseRecordDisplayed += big;				mainDatabaseRecordDisplayed = mainDatabaseRecordDisplayed < recordCount ? 					 mainDatabaseRecordDisplayed : recordCount;			 	MainFormDrawRecordView( );			}			handled = true;			break;			}	return handled;}/*********************************************************************** * FUNCTION:    	MainFormHandleDatabasePopup * * DESCRIPTION: 	This routine handles database popup events for  *                  the MainForm. * * RETURNED:    	true if the event is handled. ***********************************************************************/static Boolean MainFormHandleDatabasePopup(	// (out) returns true if event handled.	UInt16		selection 		//	(in)	the selection){	Boolean	handledEvt;		handledEvt = true;	// Set the picker name to the selected category	CategorySetTriggerLabel( GetObjectPtr( MainDatabasePopTrigger ),     		LstGetSelectionText( GetObjectPtr( MainDatabaseList ), (short)selection ) );        mainDatabaseDisplayed = (UInt16)selection;    mainDatabaseRecordDisplayed = 0;        // Redraw the views.    MainFormDrawDatabaseView( ); 	MainFormDrawRecordView( );	return handledEvt;}/*********************************************************************** * FUNCTION:    	MainFormHandleCategory * * DESCRIPTION: 	This routine handles category actions. * * RETURNED:    	true if the event is handled. ***********************************************************************/static Boolean MainFormHandleCategory(){	Boolean	catEdited 	= false;	UInt16		newCatNum 	= mainCategory;	DmOpenRef dbRef;	ControlType *popupP = GetObjectPtr( MainCategoryPopTrigger );	// kludge -- we don't ever set up the trigger's label.	CategorySetTriggerLabel( popupP, mainCategoryNameStr );	dbRef = DmOpenDatabase( 0, mainDatabaseIDList[mainDatabaseDisplayed], dmModeReadOnly);	if ( dbRef )	{				catEdited = CategorySelect ( dbRef, FrmGetActiveForm (), MainCategoryPopTrigger,			MainCategoryList, 			false, &newCatNum, 			mainCategoryNameStr,			 15, 0 );			 				// Check to see if the current category has changed in any way.		if ( catEdited || ( newCatNum != mainCategory )) {			FrmAlert( CannotChangeAlert );			MainFormDrawRecordView( );		}	}	DmCloseDatabase( dbRef );	return ( true );}/*********************************************************************** * FUNCTION:    	MainFormHandleEvent * * DESCRIPTION: 	This routine is the event handler for MainForm. * * RETURNED:    	true if the event is handled. ***********************************************************************/ static Boolean MainFormHandleEvent(	EventPtr eventP		// Pointer to an EventType that contains the event to handle){    Boolean 	handled = false;    FormPtr		frmP;	switch ( eventP->eType ) 	{	// Menu event - call MainFormDoMenuCommand to handle it.		case menuEvent:					handled = MainFormDoMenuCommand ( eventP->data.menu.itemID );			break;// Form Open. Initialize the form and draw it.		case frmOpenEvent:					frmP = FrmGetActiveForm ();			MainFormInit ( frmP );			FrmDrawForm ( frmP );			MainFormDraw( frmP );			handled = true;			break;					case frmCloseEvent:					frmP = FrmGetActiveForm ();			MainFormDone ( frmP );			FrmDeleteForm ( frmP );			handled = false; // Let OS clean up after app!			break;					case frmUpdateEvent:					frmP = FrmGetActiveForm ();			FrmDrawForm ( frmP );			MainFormDraw( frmP );			handled = true;			break; 								// Control activities		case keyDownEvent: 		if ( eventP->data.keyDown.chr == pageUpChr )		{			handled = MainFormHandleControl( MainBackButton );		}		else if ( eventP->data.keyDown.chr == pageDownChr )		{			handled = MainFormHandleControl( MainNextButton );		}					case ctlSelectEvent:			if ( eventP->data.ctlSelect.controlID == MainCategoryPopTrigger )			{				handled = MainFormHandleCategory( );				}			else						{				handled = MainFormHandleControl( eventP->data.ctlSelect.controlID );			}			break;					case popSelectEvent: // A popup list item was selected			if ( eventP->data.ctlSelect.controlID == MainDatabasePopTrigger )				handled = MainFormHandleDatabasePopup( (unsigned short)eventP->data.popSelect.selection );						break;	}	return handled;}/*********************************************************************** * 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		// Pointer to an EventType that contains 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 {		EvtGetEvent ( &event, evtWaitForever );		if (! SysHandleEvent ( &event))			if (! MenuHandleEvent ( 0, &event, &error ))				if (! AppHandleEvent ( &event ))					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 UInt32 AppStart(	void){// Return an error code if necessary. 	return 0;}/*********************************************************************** * FUNCTION:    	AppStop * * DESCRIPTION: 	Do whatever you need to do, like save the preferences. * * RETURNED:    	nothing ***********************************************************************/static void AppStop(	void){}/*********************************************************************** * FUNCTION:    PilotMain * * DESCRIPTION: The application main entry point. * * RETURNED:    0 if launch & execution are successful, non-zero otherwise. ***********************************************************************/ void AppCloseWithAlert( 	UInt16 alertID			// (in) ID of alert to show.)	{	EventPtr appStopP;	FrmAlert( alertID );	// Q an appStopEvent		appStopP = ( EventPtr )MemPtrNew( sizeof( EventType ) );		ErrFatalDisplayIf( appStopP == NULL, 			"AppCloseWithAlert cannot allocate appStopEvent!" );		MemSet( appStopP, sizeof( EventType ), 0 );		appStopP->eType = appStopEvent;		EvtAddEventToQueue( appStopP );}/*********************************************************************** * FUNCTION:    PilotMain * * DESCRIPTION: The application main entry point. * * RETURNED:    0 if launch & execution are successful, non-zero otherwise. ***********************************************************************/UInt32 PilotMain(	UInt16	cmd,					// The launch code	MemPtr	/* cmdPBP*/,		// Pointer to the launch code structure	UInt16	launchFlags			// Extra launch info){	UInt32 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 error;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -