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

📄 pakadb.c

📁 CD_高级PALM编程
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************************************************************* FILE:			PakaDB.c** DESCRIPTION:	Provides a test application to view databases built*               by the PalmDatabaseViewer application.** VERSION:		1.0**********************************************************************/#include <PalmOS.h>#include <PalmCompatibility.h>#include "PakaDB.h"#include "PakaDBRsc.h"#include "Utils.h"#include "UtilsRsc.h"#include "PalmDesktopDatabase.h"#include "User.h"/*********************************************************************** * Application constants  **********************************************************************/#define mainDatabaseBigThreshold ( 10 )/*********************************************************************** * Application globals  **********************************************************************//*********************************************************************** * Module globals  **********************************************************************/static char **mainDatabaseNameList = NULL;static LocalID *mainDatabaseIDList = NULL;static int mainDatabaseCount;static UInt16 mainDatabaseDisplayed;static UInt16 mainDatabaseRecordDisplayed;static UInt16 mainCategory = dmAllCategories;	static char	mainCategoryNameStr [ dmCategoryLength ] = "All";/*********************************************************************** * FUNCTION:    	CheckAppInfo * * DESCRIPTION: 	 * * RETURNED:    	 **********************************************************************/ static	Err  CheckAppInfo(){	UInt16		cardNo;	LocalID		dbID;	LocalID		appInfoID;	AppInfoPtr	appInfoP;	DmOpenRef dbRef;	MemHandle appInfoH = NULL;		dbRef = DmOpenDatabase( 0, mainDatabaseIDList[mainDatabaseDisplayed], dmModeReadOnly);		if ( !dbRef )		return dmErrInvalidParam;	if ( DmOpenDatabaseInfo ( dbRef, &dbID, NULL, NULL, &cardNo, NULL ))		return dmErrInvalidParam;	if ( DmDatabaseInfo ( cardNo, dbID, NULL, NULL, NULL, NULL, NULL, NULL, 		 NULL, &appInfoID, NULL, NULL, NULL))		return dmErrInvalidParam;		appInfoP = MemLocalIDToLockedPtr ( appInfoID, cardNo );	MemPtrUnlock ( appInfoP );	DmCloseDatabase( dbRef );		return ( 0 );}	/*********************************************************************** * FUNCTION:    	MainFormInit * * DESCRIPTION: 	This routine initializes the MainForm form. * * RETURNED:    	nothing ***********************************************************************/ static void MainFormInit(	FormPtr frmP		// Pointer to the MainForm form.){	ControlType *popupP;	ListPtr listP;	unsigned short int i, j;	LocalID currDB;	Err anErr;	UInt32 type,creator;	Char tempStr[32];	#pragma unused( frmP )	/*	 * initialize our form references.	 */	popupP = GetObjectPtr( MainDatabasePopTrigger );	listP = GetObjectPtr( MainDatabaseList );		/*	 * Initialize popup list with database names.	 * We assume only user-creator databases here for brevity,	 * so the user doesn't go and try to open the names database or something.	 * If you're testing your own database, be sure you substitute your own 	 * creator for this value.	 *	 * We loop twice, once to find the number of databases of ours, and once	 * to build our structures.  This is inefficient -- but so is the dynamic	 * memory gymnastics that would occur if we fold our loops.  Either way, it's	 * likely to be the same performance hit, but this is easier to debug.	 */	for ( i = 0; i < DmNumDatabases( 0 ); i++)	{		currDB = DmGetDatabase( 0, i );		anErr = DmDatabaseInfo( 0, currDB,			/* const CharPtr nameP */ NULL, 			/* UIntPtr attributesP */ NULL,			/* UIntPtr versionP */ NULL,			/* ULongPtr crDateP */ NULL,			/* ULongPtr modDateP */ NULL, 			/* ULongPtr bckUpDateP */ NULL, 			/* ULongPtr modNumP */ NULL,			/* LocalID* appInfoIDP */ NULL,			/* LocalID* sortInfoIDP */ NULL, 			&type, &creator );		// ignore errors gracefully.		if ( anErr ) continue;		if ( creator == pakaAppDataseCreatorType && type != 'appl' )		{			mainDatabaseCount++;		}	}	if ( mainDatabaseCount > 0 )	{		mainDatabaseNameList = (char **)MemPtrNew( (mainDatabaseCount) * sizeof(char *) );		mainDatabaseIDList = (LocalID *)MemPtrNew( (mainDatabaseCount) * sizeof(LocalID) );				for ( i = 0, j=0; i < DmNumDatabases( 0 ); i ++ )		{			currDB = DmGetDatabase( 0, i );			anErr = DmDatabaseInfo(0, currDB,				/* const CharPtr nameP */ tempStr, 				/* UIntPtr attributesP */ NULL,				/* UIntPtr versionP */ NULL,				/* ULongPtr crDateP */ NULL,				/* ULongPtr modDateP */ NULL, 				/* ULongPtr bckUpDateP */ NULL, 				/* ULongPtr modNumP */ NULL,				/* LocalID* appInfoIDP */ NULL,				/* LocalID* sortInfoIDP */ NULL, 				&type, &creator );			// ignore errors gracefully.			if ( anErr ) continue;			if ( creator == pakaAppDataseCreatorType && type != 'appl' )			{				mainDatabaseNameList[j]=MemPtrNew( 33 * sizeof( Char ) );				mainDatabaseIDList[j] = currDB;				StrCopy( mainDatabaseNameList[j], tempStr );				j++;			}		}		LstSetListChoices( listP, mainDatabaseNameList, mainDatabaseCount );		LstSetHeight( listP, mainDatabaseCount < 10 ? mainDatabaseCount : 10 );		LstSetSelection( listP, 0);		CtlSetLabel( popupP, LstGetSelectionText( listP, 0 ) );		MainFormDrawDatabaseView( );		MainFormDrawRecordView( );	}	else	{		/*		 * Nothing was found.		 * Say so and exit.		 */		CtlHideControl( popupP );		AppCloseWithAlert( NoDatabasesAlert );	}	mainDatabaseDisplayed = 0;	mainDatabaseRecordDisplayed = 0;	return;}/*********************************************************************** * FUNCTION:    	MainFormDrawDatabaseView * * DESCRIPTION: 	This routine draws the database info in the form. * * RETURNED:    	nothing ***********************************************************************/ static void MainFormDrawDatabaseView(	void	){	Err anErr;	UInt32 type, creator;	Char nameStr[32];	Char tempStr[32];	UInt16 version;	UInt32 creationDateSecs;	DateTimeType creationDate;				/*	 * Fetch information about the database.	 */	anErr = DmDatabaseInfo(0, mainDatabaseIDList[mainDatabaseDisplayed],		/* const CharPtr nameP */ nameStr, 		/* UIntPtr attributesP */ NULL,		/* UIntPtr versionP */ &version,		/* ULongPtr crDateP */ &creationDateSecs,		/* ULongPtr modDateP */ NULL, 		/* ULongPtr bckUpDateP */ NULL, 		/* ULongPtr modNumP */ NULL,		/* LocalID* appInfoIDP */ NULL,		/* LocalID* sortInfoIDP */ NULL, 		&type, &creator );	if ( !anErr )	{		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( (Byte)creationDate.month, 					 (Byte)creationDate.day, 					 (Word)creationDate.year, 			dfDMYLong, tempStr);		SetTextFieldWithString( MainDateField, tempStr, true );	}	else	{		FrmAlert( CantGetDatabaseInfoAlert );	}	return;}/*********************************************************************** * FUNCTION:    	MainFormDrawRecordView * * DESCRIPTION: 	This routine draws the record info in the form. * * RETURNED:    	nothing ***********************************************************************/ static void MainFormDrawRecordView(	void	){	DmOpenRef dbRef;	MemHandle recordH;	UInt32 type;	UInt attrs;	MemPtr dataP;	Char *recordStr = NULL;	Char tempStr[32];	long recordCount;	ControlType *popupP = GetObjectPtr( MainCategoryPopTrigger );	ListPtr listP = GetObjectPtr( MainCategoryList );		// Obtain info about current record.	dbRef = DmOpenDatabase( 0, mainDatabaseIDList[mainDatabaseDisplayed], dmModeReadOnly);	recordCount = (long)DmNumRecords( dbRef );	if ( recordCount > 0 )	{		recordH = DmQueryRecord( dbRef, mainDatabaseRecordDisplayed );										  		dataP = PddbRecordLock( dbRef, recordH, &type );		if ( dataP ) 		{			recordStr = UserRecordToText( type, dataP );		}		// Get the category.		DmRecordInfo( dbRef, (unsigned)mainDatabaseRecordDisplayed, &attrs, NULL, NULL);		attrs &= dmRecAttrCategoryMask;		CategoryGetName (dbRef, attrs, mainCategoryNameStr);		MemHandleUnlock( recordH );	}	DmCloseDatabase( dbRef );	// Update the fields displayed.	QuadToString( type, tempStr );	SetTextFieldWithString( MainRecTypeField, tempStr, true );	StrPrintF( tempStr, "%ld/%ld", (long)mainDatabaseRecordDisplayed + 1 , (long)recordCount );	SetTextFieldWithString( MainNumberField, tempStr, true );		CategorySetTriggerLabel( popupP, mainCategoryNameStr );	if ( StrLen( mainCategoryNameStr) > 0 )	{		CtlShowControl( popupP );			CtlDrawControl( popupP );	}	else	{		CtlHideControl( popupP );			}		SetTextFieldWithString( MainRecordField, recordStr, true );	MemPtrFree( recordStr );	// Update the buttons displayed.	MainFormDrawButtons( recordCount );	}/*********************************************************************** * FUNCTION:    	MainFormDrawButtons * * DESCRIPTION: 	This routine updates the buttons of the main form. * * RETURNED:    	nothing ***********************************************************************/ void MainFormDrawButtons(	long recordCount ) { 	ControlPtr backP, nextP;	// Show next and back buttons as appropriate.	backP = GetObjectPtr( MainBackButton );	nextP = GetObjectPtr( MainNextButton );	if ( recordCount == 0 )	{		CtlHideControl( backP );		CtlHideControl( nextP );	}	else if ( mainDatabaseRecordDisplayed == 0 )	{		CtlHideControl( backP );		CtlShowControl( nextP );		}	else if ( mainDatabaseRecordDisplayed == recordCount - 1 )	{		CtlShowControl( backP );		CtlHideControl( nextP );		}	else	{		CtlShowControl( backP );		CtlShowControl( nextP );			}	// Show the big next and back buttons as appropriate.	backP = GetObjectPtr( MainBackBigButton );	nextP = GetObjectPtr( MainNextBigButton );	if ( recordCount == 0 && recordCount > mainDatabaseBigThreshold )	{		CtlHideControl( backP );		CtlHideControl( nextP );		}	else if ( mainDatabaseRecordDisplayed == 0  && recordCount > mainDatabaseBigThreshold )	{		CtlHideControl( backP );		CtlShowControl( nextP );		}	else if ( mainDatabaseRecordDisplayed == recordCount - 1 && recordCount > mainDatabaseBigThreshold )	{		CtlShowControl( backP );		CtlHideControl( nextP );		}	else if ( recordCount > mainDatabaseBigThreshold )	{		CtlShowControl( backP );		CtlShowControl( nextP );			}		else 	{		CtlHideControl( backP );		CtlHideControl( nextP );			}}/*********************************************************************** * FUNCTION:    	MainFormDraw * * DESCRIPTION: 	This routine draws the non-form contents of the MainForm form. * * RETURNED:    	nothing ***********************************************************************/ static void MainFormDraw(	FormPtr /*frmP*/		// Pointer to the MainForm form.	){// Insert code as appropriate}/*********************************************************************** * FUNCTION:    	MainFormDone * * DESCRIPTION: 	This routine cleans up after the MainForm form. * * RETURNED:    	nothing ***********************************************************************/static void MainFormDone(	FormPtr frmP		// Pointer to the MainForm form){	int i;#pragma unused(frmP)	for ( i = 0; i < mainDatabaseCount; i++ )	{		MemPtrFree( mainDatabaseNameList[i] );	}	MemPtrFree( mainDatabaseNameList );	MemPtrFree( mainDatabaseIDList );}

⌨️ 快捷键说明

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