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

📄 gmdbview.c

📁 CD_高级PALM编程
💻 C
字号:
/********************************************************************* FILE:					GMDBView.c** DESCRIPTION:	A generic database viewer for the Global Find Project.** VERSION:			3.0**********************************************************************/#include <PalmOS.h>#include "GMDBView.h"#include "GMDBViewRsc.h"#include "Utils.h"#include "UtilsRsc.h"/*********************************************************************** * FUNCTION:    	DialogCanceled * * DESCRIPTION: 	Handle events for the progress dialog. * * RETURNED:    	true if canceled ***********************************************************************/static Boolean DialogCanceled	// ( out )  User canceled.(	ControlPtr		ctlP			// ( in ) Ptr to the cancel button control){	EventType 	event;	Boolean		canceled = false;// Check for low and high-level events.// *****This code requires a real device, not POSE, to run properly.*****	if ( EvtSysEventAvail ( false )  || EvtEventAvail ( )) 	{		EvtGetEvent ( &event, 0);		// If the cancel button has been clicked, let the caller know.		if ( event.eType == ctlSelectEvent  && 			event.data.ctlSelect.controlID == ctlP->id )		{			WinInvertRectangle ( &ctlP->bounds, 4 );			canceled = true;		}		 // Nope, let the system or the control event manager deal with it.		if ( !SysHandleEvent ( &event ))		{			CtlHandleEvent ( ctlP, &event );		}	}	return ( canceled);}/*********************************************************************** * FUNCTION:    	ScanThruDatabases * * DESCRIPTION: 	Scan throught the databases. * * RETURNED:    	nothing ***********************************************************************/static void ScanThruDatabases(	void){	UInt16			i, j;	FormPtr		frmP, saveFrmP;	Char 			tempStr [ 5 ];	ControlPtr	ctlP;	// Display the progress dialog		saveFrmP = FrmGetActiveForm ( );	frmP = FrmInitForm ( ScanningForm );	FrmDrawForm ( frmP );	FrmSetActiveForm ( frmP );		// Display the # of databases	StrIToA ( tempStr, gTotDBsNum );	WinDrawChars ( tempStr, StrLen ( tempStr ), 130, 20 );		// Get a pointer to the Cancel button for later use.	ctlP = ( ControlPtr ) GetObjectPtr ( ScanningCancelButton );			// Scan through the databases, refreshing the dialog as needed	for ( i = 0; i < gTotDBsNum; i++ )	{		StrIToA ( tempStr, i + 1 );		for ( j = 0; j < 100;  j++ )	// strictly to slow things down for demo		{			WinDrawChars ( tempStr, StrLen ( tempStr ), 102, 20 );		}			// Quit the loop if the user cancels		if ( DialogCanceled ( ctlP ))		{			break;		}	}	// Done, remove the progress dialog and restore the main form	FrmEraseForm ( frmP );	FrmDeleteForm ( frmP );	FrmSetActiveForm ( saveFrmP );}#pragma mark ----------------/*********************************************************************** * FUNCTION:    	GetRealDBIndex * * DESCRIPTION: 	Convert the virtual DB Index into a Card/Index pair. * * RETURNED:    	stores card # and DB index in passed addresses ***********************************************************************/static void GetRealDBIndex(	Int16		virIndex,	// ( in )  the virtual database number	UInt16*	cardNum,	// ( out ) the actual card number	UInt16*	dbIndex		// ( out) the actual database number)		{	UInt16		start = 0, end = 0, i = 0;// Scan thru the database counts to find the card and DB index// that the current virtual database index fits into.		do	{		end 	= end 	+ gDBCounts [ i ];		if ( virIndex >= start && virIndex < end )		{			* cardNum	= i;			* dbIndex 	= virIndex - start;			break;		}		else			start = start + gDBCounts [ i++ ];	}	while (( gDBCounts [ i ] > 0 ) && ( i < MAX_NUM_CARDS ));}/*********************************************************************** * FUNCTION:    	MoveForwardInDatabases * * DESCRIPTION: 	Names kinda says it all. * * RETURNED:    	nothing.  * * SIDE EFFECT:	Sets gVirDBIndex ***********************************************************************/static void MoveForwardInDatabases(	UInt8		increment		// ( in )  the # of databases to move forward)		{// Check to see if at end of the database list	if ( gVirDBIndex >= gTotDBsNum - 1 )	{		SndPlaySystemSound ( sndWarning );	}	else	{// No, move forward and adjust for overrun		gVirDBIndex = gVirDBIndex + increment;		if ( gVirDBIndex >= gTotDBsNum - 1 )		{			gVirDBIndex = ( Int16 ) gTotDBsNum - 1;		}		// Draw the new stuff			MainFormDraw ();	}}/*********************************************************************** * FUNCTION:    	MoveBackwardInDatabases * * DESCRIPTION: 	Refer to the function name. * * RETURNED:    	nothing.  * * SIDE EFFECT:	Sets gVirDBIndex ***********************************************************************/static void MoveBackwardInDatabases(	UInt8		increment		// ( in )  the number of database to move backwards)		{	// Check to see if at beginning of all the databases	if ( gVirDBIndex == 0 )			SndPlaySystemSound ( sndWarning );	else	{	// No, move backwards		gVirDBIndex = gVirDBIndex - increment;		if ( gVirDBIndex < 0 )			gVirDBIndex = 0;			// Draw the new info on the main form		MainFormDraw ();	}}#pragma mark ----------------/*********************************************************************** * FUNCTION:    	MainFormInit * * DESCRIPTION: 	This routine initializes the main form. * * RETURNED:    	nothing ***********************************************************************/static void MainFormInit(	FormPtr	/*frmP */		// ( in )  pointer to the main form.){	return;}/*********************************************************************** * FUNCTION:    	MainFormDraw * * DESCRIPTION: 	This routine draws the contents of the main form. * * RETURNED:    	nothing ***********************************************************************/static void MainFormDraw(	void){	UInt16					cardNum, dbIndex;	LocalID				dbID;	Err 						error;	UInt32 				type, creator;	Char 					nameStr [ 32 ];	Char 					tempStr [ 32 ];	UInt16 				version;	UInt32 				creationDateSecs;	DateTimeType	creationDate;	// Get the card number & database index	GetRealDBIndex ( gVirDBIndex, &cardNum, &dbIndex );	// Get the database ID			dbID = DmGetDatabase ( cardNum, dbIndex );	if ( dbID )	{	// Get the database info		error = DmDatabaseInfo ( cardNum, dbID, nameStr, NULL, 			&version, &creationDateSecs, NULL,  NULL,  NULL, NULL,  NULL, 			&type, &creator );		if ( ! error )		{		// Convert the various pieces of data for main form and// put them on the screen			StrIToA ( tempStr, ( cardNum + 1 ) );			SetTextFieldWithString  ( MainCardField, tempStr, true );						StrIToA ( tempStr, gMaxCardsNum );			SetTextFieldWithString  ( MainNumCardsField, tempStr, true );						StrIToA ( tempStr, ( dbIndex + 1 ));			SetTextFieldWithString  ( MainDBIndexField, tempStr, true );			StrIToA ( tempStr, gDBCounts [ cardNum ] );			SetTextFieldWithString  ( MainNumDBsField, tempStr, true );						SetTextFieldWithString( MainDBNameField, nameStr, true );					QuadToString ( type, tempStr );			SetTextFieldWithString ( MainTypeField, tempStr, true );					QuadToString ( creator, tempStr );			SetTextFieldWithString ( MainCreatorField, tempStr, true );					StrIToA ( tempStr, version );			SetTextFieldWithString  ( MainVersionField, tempStr, true );					TimSecondsToDateTime( creationDateSecs, &creationDate );			DateToAscii (				( UInt8 ) creationDate.month, ( UInt8 ) creationDate.day, 				( UInt16 ) creationDate.year, dfDMYLong, tempStr );			SetTextFieldWithString ( MainDateField, tempStr, true );		}		else			FrmAlert ( CantGetDatabaseInfoAlert );	}	else		FrmAlert ( CantGetDatabaseInfoAlert );}/*********************************************************************** * FUNCTION:    	MainFormDone * * DESCRIPTION: 	This routine cleans up after the main form. * * RETURNED:    	nothing ***********************************************************************/static void MainFormDone(	FormPtr	frmP		//  ( in) Pointer to the main form){	if ( frmP != NULL )	{	// Insert application-specific code first// Then do this as the very last thing		FrmEraseForm	( frmP );		FrmDeleteForm	( frmP );	}}/*********************************************************************** * FUNCTION:    	MainFormDoMenuCommand * * DESCRIPTION: 	This routine handles menu commands. * * RETURNED:    	nothing ***********************************************************************/static Boolean MainFormDoMenuCommand  // ( out ) handled?(	UInt16 	command			// ( in ) The ID of menu command to do){	Boolean 		handled = false;	FormPtr 		frmP;	MenuEraseStatus ( 0 );	switch ( command )	{		case MainOptionsAboutGMDBViewer:					frmP = FrmInitForm ( AboutForm );			FrmDoDialog ( frmP );			FrmDeleteForm ( frmP );			handled = true;			break;					case MainOptionsScantheDatabases:			ScanThruDatabases ();			handled = true;			break;	}	return handled;}/*********************************************************************** * FUNCTION:    	MainFormHandleControl * * DESCRIPTION: 	This routine handles control events for the main. * * RETURNED:    	true if the event is handled. ***********************************************************************/static Boolean MainFormHandleControl	// ( out ) event handled?(		UInt16			controlID	// ( in )  the ID  of the control)		{	Boolean		handled = true;		switch( controlID )	{		case MainNextButton:			MoveForwardInDatabases ( 1 );			break;					case MainBackButton:			MoveBackwardInDatabases ( 1 );			break;						case MainBigNextButton:			MoveForwardInDatabases ( BIG_JUMP );			break;					case MainBigPrevButton:			MoveBackwardInDatabases ( BIG_JUMP );			break;					default:			handled = false;	}	return handled;}/*********************************************************************** * FUNCTION:    	MainFormHandleEvent * * DESCRIPTION: 	This routine is the event handler for main. * * RETURNED:    	true if the event is handled. ***********************************************************************/static Boolean MainFormHandleEvent	// ( out ) event handled?(	EventPtr eventP		// ( in )  pointer to the event to handle){    Boolean 	handled 	= false;    FormPtr	frmP 		= FrmGetActiveForm ();	if ( frmP )	{		switch ( eventP->eType ) 		{		// Form events			case frmOpenEvent:				MainFormInit ( frmP );	// ***** Falls thru to next case							case frmUpdateEvent:				FrmDrawForm ( frmP );				MainFormDraw ();				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:				handled = MainFormHandleControl ( eventP->data.ctlSelect.controlID );				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 // ( out ) event handled?(	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 {		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:     	zero.  * * SIDE EFFECT:	sets globals gDBCounts, gTotDBsNum, and gMaxCardsNum. ***********************************************************************/static UInt32 AppStart	// ( out ) error code or zero(	void){	UInt16		i = 0;	UInt32		result = 0;// Scan thru the storage cards fetching database counts		do	{		gDBCounts [ i ] = DmNumDatabases ( i );		gTotDBsNum 	= gTotDBsNum + gDBCounts [ i ];		if ( gDBCounts [ i ] > 0 )		{			gMaxCardsNum = i + 1;		}	} 	while (( gDBCounts [ i++ ] != 0 ) && ( i < MAX_NUM_CARDS ));	return result;}/*********************************************************************** * FUNCTION:    	AppStop * * DESCRIPTION: 	Do whatever you need to do, like save the preferences. * * RETURNED:    	nothing ***********************************************************************/static void AppStop(	void){	FrmCloseAllForms ();}/*********************************************************************** * FUNCTION:   		PilotMain * * DESCRIPTION: 	The application main entry point. * * RETURNED:    	0 if launch & execution are successful, non-zero otherwise. ***********************************************************************/UInt32 PilotMain	// ( out ) error code or zero(	UInt16	cmd,						// ( in )  the launch code	MemPtr	/* cmdPBP*/,		// ( in )  pointer to the launch code structure	UInt16	launchFlags			// ( in )  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 + -