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

📄 addrview.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
📖 第 1 页 / 共 5 页
字号:
		// Switch fonts if necessary before computing the extra vertical
		// space needed for this element of the array.
		if (i == RecordViewFirstPlainLine)
			FntSetFont (AddrRecordFont);
		currentHeight = PrvViewCalcNextLine(i, FntLineHeight());

		// Since the above function returns zero for all but the first
		// item when several should be drawn at the same y coordinate,
		// we need to delay adding the result until we get to the next
		// non-zero result.
		if (currentHeight != 0)
		{
			lineY += previousNonZeroHeight;
			previousNonZeroHeight = currentHeight;
		}

		// If we are past the bottom stop drawing
		if (lineY > bottomOfRecordViewDisplay - FntLineHeight())
			break;

		ErrNonFatalDisplayIf(lineY < r.topLeft.y, "Searching for record out of gadget");

		// The remainder of the fields' lines were drawn without any other special
		// handling. These may include continuations of phone numbers that don't
		// fit on one line as well as entire phone numbers which were included in
		// a field, separated by the return stroke.

		// Check if this is a dialable phone
		if ((RecordViewLines[i].fieldNum >= firstPhoneField)
			&& (RecordViewLines[i].fieldNum <= lastPhoneField)
			&& (ToolsIsPhoneIndexSupported(&recordViewRecord, RecordViewLines[i].fieldNum - firstPhoneField)))
		{
			// Dial the number tapped on.
			width = FntCharsWidth
				(&recordViewRecord.fields[RecordViewLines[i].fieldNum][RecordViewLines[i].offset],
				 RecordViewLines[i].length);
			height = FntCharHeight();
			RctSetRectangle(&r, RecordViewLines[i].x, lineY, width, height);
			if (RctPtInRectangle (x, y, &r))
			{
				*fieldNumP = RecordViewLines[i].fieldNum;

				// Look to see if this phone number started on a previous line.
				for (; i != 0; i--)
				{
					if (RecordViewLines[i - 1].fieldNum != *fieldNumP)
						break;
					if (recordViewRecord.fields[*fieldNumP][RecordViewLines[i].offset - 1] == linefeedChr)
						break;
				}
				*offsetP = RecordViewLines[i].offset;
				*lengthP = RecordViewLines[i].length;

				// Look to see if this phone number continues on subsequent lines.
				for (j = i + 1; j < RecordViewLastLine; j++)
				{
					if (RecordViewLines[j].fieldNum != *fieldNumP)
						break;
					if (recordViewRecord.fields[*fieldNumP][RecordViewLines[j].offset - 1] == linefeedChr)
						break;
					*lengthP += RecordViewLines[j].length;
				}

				FntSetFont (curFont);
				return true;
			}
		}
	}

	FntSetFont (curFont);
	return false;		// Given point isn't in a phone number.
}


/***********************************************************************
 *
 * FUNCTION:    PrvViewHandleTapOnPhoneNumber
 *
 * DESCRIPTION: Handle a tap on a phone number in the RecordViewDisplay.
 *					 Highlight the phone number while the pen is over it, and
 *					 dial if the pen is released over it.
 *
 * PARAMETERS:  	fieldNum	- which field
 *					offset		- start of phone number in field
 *					length		- length of phone number in field
 *
 * RETURNED:    Whether Dial Number screen has been displayed
 *
 * REVISION HISTORY:
 *		Name	Date		Description
 *		----	----		-----------
 *		peter	05/05/00	Initial Revision
 *		aro		06/27/00	Add dialing
 *		fpa		10/19/00	Returns a boolean
 *
 ***********************************************************************/
Boolean PrvViewHandleTapOnPhoneNumber (UInt16 fieldNum, UInt16 offset, UInt16 length)
{
	UInt16			testFieldNum, testOffset, testLength;
	Int16				testX, testY;
	Boolean			isPenDown, wasSelected, isSelected;
	FormType*		frmP;

	frmP = FrmGetActiveForm();
	wasSelected = true;
	PrvViewDraw(frmP, fieldNum, offset, length, true);

	do
	{
		PenGetPoint (&testX, &testY, &isPenDown);
		isSelected = PrvViewPhoneNumberAt(testX, testY, &testFieldNum, &testOffset, &testLength) &&
			testFieldNum == fieldNum && testOffset == offset;
		if (isSelected != wasSelected)
		{
			PrvViewDraw(frmP,fieldNum, offset, isSelected ? length : 0, true);
			wasSelected = isSelected;
		}
	} while (isPenDown);

	if (isSelected)
	{
		UInt16 lineIndex;
		PrvViewDraw(frmP, fieldNum, offset, 0, true);

		lineIndex = ToolsGetLineIndexAtOffset(recordViewRecord.fields[fieldNum], offset);
		return DialListShowDialog(CurrentRecord, fieldNum - firstPhoneField, lineIndex);
	}
	else
		return false;
}


/***********************************************************************
 *
 * FUNCTION:    PrvViewHandlePen
 *
 * DESCRIPTION: Handle pen movement in the RecordViewDisplay. If the user
 *					 taps in the RecordViewDisplay take them to the Edit View
 *					 unless they tap on a phone number. In that case, arrange
 *					 to dial the selected number.
 *
 * PARAMETERS:  event  - a pointer to an EventType structure
 *
 * RETURNED:    true if handled.
 *
 * REVISION HISTORY:
 *		Name	Date		Description
 *		----	----		-----------
 *		roger	11/27/95	Cut from RecordViewHandleEvent
 *		peter	05/03/00	Add support for tapping on phone numbers to dial
 *      aro     06/27/00    Check for dialing abilities
 *
 ***********************************************************************/
Boolean PrvViewHandlePen (EventType * event)
{
	FormPtr			frm;
	RectangleType	r;
	Int16				x, y;
	Boolean			isPenDown;
	UInt16			fieldNum, offset, length;

	frm = FrmGetActiveForm();
	FrmGetObjectBounds(frm, FrmGetObjectIndex(frm, RecordViewDisplay), &r);
	if (! RctPtInRectangle (event->screenX, event->screenY, &r))
		return false;

	// Check if the user tapped on a phone number.
	if (EnableTapDialing)
	{
		if (PrvViewPhoneNumberAt (event->screenX, event->screenY, &fieldNum, &offset, &length))
		{
			// The user tapped on this phone number. Wait for the pen up, highlighting the
			// phone number when the pen is over the number.
			if ( PrvViewHandleTapOnPhoneNumber (fieldNum, offset, length) )
				return true;
		}
	}

	// The user tapped in the record view display, but not on a phone number,
	// so wait for the pen to be released and if it's released inside the
	// record view display, edit the record.
	do
	{
		PenGetPoint (&x, &y, &isPenDown);
	} while (isPenDown);
	if (RctPtInRectangle (x, y, &r))
		FrmGotoForm (EditView);

	return true;
}


/***********************************************************************
 *
 * FUNCTION:    PrvViewDoCommand
 *
 * DESCRIPTION: This routine performs the menu command specified.
 *
 * PARAMETERS:  command  - menu item id
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *         Name   Date       Description
 *         ----   ----       -----------
 *         roger  06/27/95   Initial Revision
 *         jmp    09/17/99   Use NewNoteView instead of NoteView.
 *         FPa    11/20/00   Fixed a memory leak when deleting a note
 *         FPa    01/26/00   Fixed bug #51545
 *
 ***********************************************************************/
Boolean PrvViewDoCommand (UInt16 command)
{
	UInt16 newRecord;
	UInt16 numCharsToHilite;
	FormType *frmP;
	FontID oldFont;

	switch (command)
	{
	case RecordRecordDeleteRecordCmd:
		if (DetailsDeleteRecord ())
		{
			recordViewRecordH = 0;      // freed by the last routine
			FrmGotoForm (ListView);
		}
		return true;

	case RecordRecordDuplicateAddressCmd:
		newRecord = ToolsDuplicateCurrentRecord (&numCharsToHilite, false);
		// If we have a new record take the user to be able to edit it
		// automatically.
		if (newRecord != noRecord)
		{
			NumCharsToHilite = numCharsToHilite;
			CurrentRecord = newRecord;
			FrmGotoForm (EditView);
		}
		return true;

	case RecordRecordDialCmd:
		MenuEraseStatus (0);
		DialListShowDialog(CurrentRecord, kDialListShowInListPhoneIndex, 0);
		return true;

	case RecordRecordAttachNoteCmd:
		if (NoteViewCreate())
			FrmGotoForm (NewNoteView);
		// CreateNote may or may not have freed the record.  Compare
		// the record's handle to recordViewRecordH.  If they differ
		// the record is new and recordViewRecordH shouldn't be freed
		// by the frmClose.
		if (recordViewRecordH != DmQueryRecord(AddrDB, CurrentRecord))
			recordViewRecordH = 0;
		return true;

	case RecordRecordDeleteNoteCmd:
		if (recordViewRecord.fields[note] != NULL &&
			FrmAlert(DeleteNoteAlert) == DeleteNoteYes)
		{
			FormType* frmP;
		
			// Free recordViewRecordH because recordViewRecordH() calls AddrDBGetRecord()
			if (recordViewRecordH)
			{
				MemHandleUnlock(recordViewRecordH);
				recordViewRecordH = 0;
			}

			NoteViewDelete ();
			// Deleting the note caused the record to be unlocked
			// Get it again for the record view's usage
			AddrDBGetRecord (AddrDB, CurrentRecord, &recordViewRecord, &recordViewRecordH);

			// Initialize RecordViewLines, RecordViewLastLine... so that the Note won't be drawn
		  	frmP = FrmGetActiveForm();
	  		PrvViewInit(frmP);

			PrvViewUpdate(frmP);
		}
		return true;

	case RecordRecordSelectBusinessCardCmd:
		MenuEraseStatus (0);
		if (FrmAlert(SelectBusinessCardAlert) == SelectBusinessCardYes)
		{
			DmRecordInfo (AddrDB, CurrentRecord, NULL, &BusinessCardRecordID, NULL);
			PrvViewDrawBusinessCardIndicator (FrmGetActiveForm());
		}
		return true;

	case RecordRecordBeamBusinessCardCmd:
		MenuEraseStatus (0);
		ToolsAddrBeamBusinessCard(AddrDB);
		return true;

	case RecordRecordBeamRecordCmd:
		MenuEraseStatus (0);
		TransferSendRecord(AddrDB, CurrentRecord, exgBeamPrefix, NoDataToBeamAlert);
		return true;

	case RecordRecordSendRecordCmd:
		MenuEraseStatus (0);
		TransferSendRecord(AddrDB, CurrentRecord, exgSendPrefix, NoDataToSendAlert);
		return true;

	case RecordOptionsFontCmd:
		MenuEraseStatus (0);
		oldFont = AddrRecordFont;
		AddrRecordFont = ToolsSelectFont (AddrRecordFont);
		if (oldFont != AddrRecordFont)
		{
			PrvViewClose();
			frmP = FrmGetFormPtr(RecordView);
			PrvViewInit(frmP);
		}
		return true;

	case RecordOptionsEditCustomFldsCmd:
		MenuEraseStatus (0);
		FrmPopupForm (CustomEditDialog);
		return true;

	case RecordOptionsAboutCmd:
		MenuEraseStatus (0);
		AbtShowAbout (sysFileCAddress);
		return true;

	}

	return false;
}

#pragma mark -

#if USE_TEMPLATES

/***********************************************************************
 *
 * FUNCTION:    PrvViewInitUsingTemplate
 *
 * DESCRIPTION: This routine initializes the "Record View" of the
 *              Address application using the template engine if it exists.  
 *					 Most importantly it lays out the record and decides 
 *              how the record is drawn.
 *
 * PARAMETERS:  appInfoPtr - pointer to the app info block.
 *					 maxWidth - maximum width available for the laying out of
 *					  				fields.
 *
 * RETURNED:    true if the template engine could be used
 *              false if no templates exist.
 *
 * REVISION HISTORY:
 *        	Name   	Date      	Description
 *        	----   	----      	-----------
 *        	vivek  	10/23/02   	Initial Revision
 *
 ***********************************************************************/
Boolean PrvViewInitUsingTemplate(AddrAppInfoPtr appInfoPtr, UInt16 maxWidth)
{

	FontID curFont;
	MemHandle addrLayoutH;
	
	// First get the View layout driver resource
	
	addrLayoutH = DmGetResource(constantRscType, enableTemplatesConstRscID);
	ErrNonFatalDisplayIf(!addrLayoutH, "tint 1700 needs to be defined.");
	if (addrLayoutH)
	{
		UInt32 enableTemplates;
		
		enableTemplates = *(UInt32 *) MemHandleLock (addrLayoutH);
		MemHandleUnlock (addrLayoutH);
		DmReleaseResource (addrLayoutH);
		
		if (enableTemplates == 0)
			return false;
	}
	else
	{
		// If the resource doesn't exist (should never happen), then just return back 
		// to do things the old way.
		return false;
	}
	
		
	RecordViewLayoutRowNum = 0;	

	// The first layout is always the heading and its font is set up differently
	curFont = FntSetFont (largeBoldFont);
	PrvAddSpaceForBlockLayout(&recordViewRecord, appInfoPtr, kViewBlockLayout_Header, maxWidth);
	PrvAddSpaceForBlockLayout(&recordViewRecord, appInfoPtr, kViewBlockLayout_Phones, maxWidth);
	PrvAddSpaceForBlockLayout(&recordViewRecord, appInfoPtr, kViewBlockLayout_Body, maxWidth);
	PrvAddSpaceForBlockLayout(&recordViewRecord, appInfoPtr, kViewBlockLayout_Custom, maxWidth);
	PrvAddSpaceForBlockLayout(&recordViewRecord, appInfoPtr, kViewBlockLayout_Note, maxWidth);
	

	// Now remove trailing blank lines
	while (RecordViewLastLine > 0 &&
		   RecordViewLines[RecordViewLa

⌨️ 快捷键说明

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