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

📄 addrlist.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
📖 第 1 页 / 共 4 页
字号:

	// Load records into the address list.
	PrvListLoadTable(frmP);


	// Set the label of the category trigger.
	ctl = ToolsGetFrmObjectPtr(frmP, ListCategoryTrigger);
	CategoryGetName (AddrDB, CurrentCategory, CategoryName);
	CategorySetTriggerLabel (ctl, CategoryName);
}


/***********************************************************************
 *
 * FUNCTION:    PrvListResetScrollRate
 *
 * DESCRIPTION: This routine resets the scroll rate
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name		Date		Description
 *			----		----		-----------
 *			frigino	8/14/97	Initial Revision
 *
 ***********************************************************************/
void PrvListResetScrollRate(void)
{
	// Reset last seconds
	LastSeconds = TimGetSeconds();
	// Reset scroll units
	ScrollUnits = 1;
}


/***********************************************************************
 *
 * FUNCTION:    PrvListAdjustScrollRate
 *
 * DESCRIPTION: This routine adjusts the scroll rate based on the current
 *              scroll rate, given a certain delay, and plays a sound
 *              to notify the user of the change
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name		Date		Description
 *			----		----		-----------
 *			frigino		8/14/97		Initial Revision
 *			vmk			12/2/97		Fix crash from uninitialized sndCmd and
 *									derive sound amplitude from system amplitude
 *
 ***********************************************************************/
void PrvListAdjustScrollRate(void)
{
	// Accelerate the scroll rate every 3 seconds if not already at max scroll speed
	UInt16 newSeconds = TimGetSeconds();
	if ((ScrollUnits < scrollSpeedLimit) && ((newSeconds - LastSeconds) > scrollDelay))
	{
		// Save new seconds
		LastSeconds = newSeconds;

		// increase scroll units
		ScrollUnits += scrollAcceleration;
	}

}


/***********************************************************************
 *
 * FUNCTION:    PrvListLookupString
 *
 * DESCRIPTION: Adds a character to ListLookupField, looks up the
 * string in the database and selects the item that matches.
 *
 * PARAMETERS:  event - EventType* containing character to add to ListLookupField
 *
 * RETURNED:    true if the field handled the event
 *
 * REVISION HISTORY:
 * 	Name	Date		Description
 *	----	----		-----------
 *	roger	6/15/95		Initial Revision
 *	vsm		11/6/02		Disable the deletion of the last input character
 *						if it didn't match any record in the list as it 
 *						doesn't work for multi-byte encodings.
 *
 ***********************************************************************/
Boolean PrvListLookupString (EventType * event)
{
	FormType* frmP;
	UInt16 fldIndex;
	FieldPtr fldP;
	Char * fldTextP;
	TablePtr tableP;
	UInt16 foundRecord;
	Boolean completeMatch;
#if 0
	Int16 length;
#endif

	frmP = FrmGetActiveForm();
	fldIndex = FrmGetObjectIndex(frmP, ListLookupField);
	FrmSetFocus(frmP, fldIndex);
	fldP = FrmGetObjectPtr (frmP, fldIndex);


	if (FldHandleEvent (fldP, event) || event->eType == fldChangedEvent)
	{
		fldTextP = FldGetTextPtr(fldP);
		tableP = ToolsGetFrmObjectPtr(frmP, ListTable);

		if (!AddrDBLookupString(AddrDB, fldTextP, SortByCompany,
							  CurrentCategory, &foundRecord, &completeMatch,
							  (PrivateRecordVisualStatus == maskPrivateRecords)))
		{
			// If the user deleted the lookup text remove the
			// highlight.
			CurrentRecord = noRecord;
			TblUnhighlightSelection(tableP);
		}
		else
		{
			PrvListSelectRecord(frmP, foundRecord, true);
		}

#if 0
		// This "feature" works only for input that isn't coming through the FEP
		// so I could add the check "&& (TsmGetFepMode(NULL) == tsmFepModeOff)"
		// but then I would also have to fix up the deletion so that only a proper
		// "character" is deleted. 
		// The right way to do this would be set up a 'tint' resource that would specify
		// whether we need to delete the last character if we didn't match.
		if (!completeMatch)
		{
			// Delete the last character added.
			length = FldGetTextLength(fldP);
			FldDelete(fldP, length - 1, length);

			SndPlaySystemSound (sndError);
		}
#endif

		return true;
	}

	// Event not handled
	return false;

}


/***********************************************************************
 *
 * FUNCTION:    PrvListDrawRecord
 *
 * DESCRIPTION: This routine draws an address book record.  It is called as
 *              a callback routine by the table object.
 *
 * PARAMETERS:  table  - pointer to the address list table
 *              row    - row number, in the table, of the item to draw
 *              column - column number, in the table, of the item to draw
 *              bounds - bounds of the draw region
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *         Name   Date      Description
 *         ----   ----      -----------
 *         roger   6/21/95   Initial Revision
 *			  peter	 5/09/00	  Store phoneX in row data for tap test
 *
 ***********************************************************************/
void PrvListDrawRecord (void * table, Int16 row, Int16 column, RectanglePtr bounds)
{
	UInt16 recordNum;
	Err error;
	AddrDBRecordType record;
	MemHandle recordH;
	char noteChar;
	FontID currFont;
	Int16 phoneX;

	// Get the record number that corresponds to the table item to draw.
	// The record number is stored in the "intValue" field of the item.
	//
	recordNum = TblGetRowID (table, row);

	error = AddrDBGetRecord (AddrDB, recordNum, &record, &recordH);
	if (error)
	{
		ErrNonFatalDisplay ("Record not found");
		return;
	}

	switch (column)
	{
		case nameAndNumColumn:
			currFont = FntSetFont (AddrListFont);
			phoneX = ToolsDrawRecordNameAndPhoneNumber (&record, bounds, PhoneLabelLetters, SortByCompany, &UnnamedRecordStringPtr, &UnnamedRecordStringH);
			FntSetFont (currFont);
			TblSetRowData(table, row, phoneX);			// Store in table for later tap testing
			break;
		case noteColumn:
			// Draw a note symbol if the field has a note.
			if (record.fields[note])
			{
				currFont = FntSetFont (symbolFont);
				noteChar = symbolNote;
				WinDrawChars (&noteChar, 1, bounds->topLeft.x, bounds->topLeft.y);
				FntSetFont (currFont);
			}
		break;
	}

	MemHandleUnlock(recordH);
}


/***********************************************************************
 *
 * FUNCTION:    PrvListClearLookupString
 *
 * DESCRIPTION: Clears the ListLookupField.  Does not unhighlight the item.
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *         Name   Date      Description
 *         ----   ----      -----------
 *         roger   6/16/95   Initial Revision
 *
 ***********************************************************************/
void PrvListClearLookupString ()
{
	FormType* frmP;
	FieldType* fldP;
	Int16 length;

	frmP = FrmGetActiveForm();
	FrmSetFocus(frmP, noFocus);
	fldP = ToolsGetFrmObjectPtr(frmP, ListLookupField);

	length = FldGetTextLength(fldP);
	if (length > 0)
	{
		// Clear it this way instead of with FldDelete to avoid sending a
		// fldChangedEvent (which would undesirably unhighlight the item).
		FldFreeMemory (fldP);
		FldDrawField (fldP);
	}
}


/***********************************************************************
 *
 * FUNCTION:    PrvListNumberOfRows
 *
 * DESCRIPTION: This routine return the maximun number of visible rows,
 *              with the current list view font setting.
 *
 * PARAMETERS:  table - List View table
 *
 * RETURNED:    maximun number of displayable rows
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	8/28/97	Initial Revision
 *
 ***********************************************************************/
UInt16 PrvListNumberOfRows (TablePtr table)
{
	UInt16				rows;
	UInt16				rowsInTable;
	UInt16				tableHeight;
	FontID			currFont;
	RectangleType	r;


	rowsInTable = TblGetNumberOfRows (table);

	TblGetBounds (table, &r);
	tableHeight = r.extent.y;

	currFont = FntSetFont (AddrListFont);
	rows = tableHeight / FntLineHeight ();
	FntSetFont (currFont);

	if (rows <= rowsInTable)
		return (rows);
	else
		return (rowsInTable);
}


/***********************************************************************
 *
 * FUNCTION:    PrvListUpdateScrollButtons
 *
 * DESCRIPTION: Show or hide the list view scroll buttons.
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *        	Name   Date      	Description
 *        	----   ----      	-----------
 *       	roger   6/21/95   	Initial Revision
 *			aro		9/25/00		Adding frmP as a parameter for frmUpdateEvent
 *
 ***********************************************************************/
void PrvListUpdateScrollButtons( FormType* frmP )
{
	UInt16 row;
	UInt16 upIndex;
	UInt16 downIndex;
	UInt16 recordNum;
	Boolean scrollableUp;
	Boolean scrollableDown;
	TableType* tblP;

	// Update the button that scroll the list.
	//
	// If the first record displayed is not the fist record in the category,
	// enable the up scroller.
	recordNum = TopVisibleRecord;
	scrollableUp = ToolsSeekRecord (&recordNum, 1, dmSeekBackward);


	// Find the record in the last row of the table
	tblP = ToolsGetFrmObjectPtr(frmP, ListTable);
	row = TblGetLastUsableRow(tblP);
	if (row != tblUnusableRow)
		recordNum = TblGetRowID(tblP, row);


	// If the last record displayed is not the last record in the category,
	// enable the down scroller.
	scrollableDown = ToolsSeekRecord (&recordNum, 1, dmSeekForward);

	// Update the scroll button.
	upIndex = FrmGetObjectIndex(frmP, ListUpButton);
	downIndex = FrmGetObjectIndex(frmP, ListDownButton);
	FrmUpdateScrollers(frmP, upIndex, downIndex, scrollableUp, scrollableDown);
}


/***********************************************************************
 *
 * FUNCTION:    PrvListLoadTable
 *
 * DESCRIPTION: This routine loads address book database records into
 *              the list view form.
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *      Name   	Date      	Description
 *      ----   	----      	-----------
 *      art  	6/5/95      Initial Revision
 *		aro		9/25/00		Adding frmP as a parameter for frmUpdateEvent
 *
 ***********************************************************************/
void PrvListLoadTable( FormType* frmP )
{
	UInt16      row;
	UInt16      numRows;
	UInt16		lineHeight;
	UInt16		recordNum;
	UInt16		visibleRows;
	FontID		currFont;
	TableType* 	tblP;
	UInt16 		attr;
	Boolean		masked;


	// For each row in the table, store the record number as the row id.
	tblP = ToolsGetFrmObjectPtr(frmP, ListTable);

	TblUnhighlightSelection(tblP);

	// Make sure we haven't scrolled too far down the list of records
	// leaving blank lines in the table.

	// Try going forward to the last record that should be visible
	visibleRows = PrvListNumberOfRows(tblP);
	recordNum = TopVisibleRecord;
	if (!ToolsSeekRecord (&recordNum, visibleRows - 1, dmSeekForward))
	{
		// We have at least one line without a record.  Fix it.
		// Try going backwards one page from the last record
		TopVisibleRecord = dmMaxRecordIndex;
		if (!ToolsSeekRecord (&TopVisibleRecord, visibleRows - 1, dmSeekBackward))
		{
			// Not enough records to fill one page.  Start with the first record
			TopVisibleRecord = 0;
			ToolsSeekRecord (&TopVisibleRecord, 0, dmSeekForward);
		}
	}


	currFont = FntSetFont (AddrListFont);
	lineHeight = FntLineHeight ();
	FntSetFont (currFont);

	numRows = TblGetNumberOfRows(tblP);
	recordNum = TopVisibleRecord;

	for (row = 0; row < visibleRows; row++)
	{
		if ( ! ToolsSeekRecord (&recordNum, 0, dmSeekForward))
			break;

		// Make the row usable.
		TblSetRowUsable (tblP, row, true);

		DmRecordInfo (AddrDB, recordNum, &attr, NULL, NULL);
		masked = (((attr & dmRecAttrSecret) && PrivateRecordVisualStatus == maskPrivateRecords));
		TblSetRowMasked(tblP,row,masked);

		// Mark the row invalid so that it will draw when we call the
		// draw routine.
		TblMarkRowInvalid (tblP, row);

		// Store the record number as the row id.
		TblSetRowID (tblP, row, recordNum);

		TblSetItemFont (tblP, row, nameAndNumColumn, AddrListFont);
		TblSetRowHeight (tblP, row, lineHeight);

		recordNum++;
	}


	// Hide the item that don't have any data.

⌨️ 快捷键说明

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