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

📄 addrdiallist.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
📖 第 1 页 / 共 2 页
字号:
			{
				ToolsGetStringResource (nameLayoutFMap.separatorStrID, separatorStr);
				
				gDisplayName = PrvDialListAllocStringFrom(gAddrP->fields[nameLayoutFMap.firstFieldNum], separatorStr, 
								gAddrP->fields[nameLayoutFMap.secondFieldNum], true);
			}
			else
			{
				gDisplayName = PrvDialListAllocStringFrom(gAddrP->fields[firstName], " ", gAddrP->fields[name], true);
			}
		}
		else
		{
			// first name only
			gDisplayName = PrvDialListAllocStringFrom(gAddrP->fields[firstName], 0, 0, true);
		}
	}
	else
	{
		if (gAddrP->fields[name])
		{
			// name only
			gDisplayName = PrvDialListAllocStringFrom(gAddrP->fields[name], 0, 0, true);
		}
		else if (gAddrP->fields[company])
		{
			// company only
			gDisplayName = PrvDialListAllocStringFrom(gAddrP->fields[company], 0, 0, true);
		}
	}

	if (!gDisplayName)
	{
		MemHandle unnamedH;
		// - unnamed - (need allocation)
		unnamedH = DmGetResource(strRsc, UnnamedRecordStr);
		gDisplayName = PrvDialListAllocStringFrom(MemHandleLock(unnamedH), 0, 0, true);
		MemHandleUnlock(unnamedH);
	}
}


/***********************************************************************
 *
 * FUNCTION:
 *	PrvDialListHandleDescriptionEvent
 *
 * DESCRIPTION:
 *	This routine handle gadget event for descrption (mainly drawing)
 *
 * PARAMETERS
 *	gadgetP	IN  gadget pointer
 *	cmd		IN	command
 *	paramP	IN	param (unused)
 *
 * RETURNED:
 *	nothing
 *
 * REVISION HISTORY:
 *	Name	Date		Description
 *	----	----		-----------
 *	aro		08/02/00	Initial Revision
 *
 ***********************************************************************/
#ifdef FORM_GADGET_TYPE_IN_CALLBACK_DEFINED // Added for Compatibility with SDK 4.0 update 1
Boolean PrvDialListHandleDescriptionEvent( struct FormGadgetTypeInCallback *gadgetP, UInt16 cmd, void *paramP )
#else
Boolean PrvDialListHandleDescriptionEvent( struct FormGadgetType *gadgetP, UInt16 cmd, void *paramP )
#endif
{
#pragma unused(paramP)

	Boolean handled = false;
	FormType *gadgetFormP;
	UInt16 gadgetIndex;
	RectangleType gadgetBounds;

	switch (cmd)
	{
	case formGadgetDeleteCmd:
		// Free the display Name
		break;
	case formGadgetDrawCmd:
		{
			FontID fontId;

			// Get the bounds of the gadget from the form
			gadgetFormP = FrmGetActiveForm();
			if (gadgetFormP == NULL)
				goto Done;
			gadgetIndex = FrmGetObjectIndexFromPtr(gadgetFormP, gadgetP);
			if ( gadgetIndex == frmInvalidObjectId )
				goto Done;
			FrmGetObjectBounds(gadgetFormP, gadgetIndex, &gadgetBounds);
			// The displayName is left-aligned and truncated to fit in the gadget
			fontId = FntSetFont(largeBoldFont);
			WinDrawTruncChars(gDisplayName, StrLen(gDisplayName), gadgetBounds.topLeft.x, gadgetBounds.topLeft.y,
							  gadgetBounds.extent.x);
			FntSetFont(fontId);
			handled = true;
			break;
		}
	}
Done:
	return handled;
}


/***********************************************************************
 *
 * FUNCTION:    PrvDialListInit
 *
 * DESCRIPTION: This routine initializes the "Dial List" dialog of the
 *              Address application.
 *
 * PARAMETERS:  frmP  - a pointer to the Form
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name		Date		Description
 *			----		----		-----------
 *			aro			6/12/00		Initial Revision
 *
 ***********************************************************************/
void PrvDialListInit( FormType* frmP )
{
	ListType*	lstP;
	UInt16		fldIndex;
	FieldType*	fldP;
	const Char*	description = "";
	Coord		dummy;
	Int16		middle;
	Int16		visibleItems;
	Int16		topIndex;

	// Build the description for drawing in the form
	PrvDialListBuildDescription();
	FrmSetGadgetHandler(frmP, FrmGetObjectIndex(frmP, DialListDescriptionGadget), PrvDialListHandleDescriptionEvent);

	// Get the gadget phone rectangle position, since phone in the list will be aligned to that
	FrmGetObjectPosition(frmP, FrmGetObjectIndex(frmP, DialListPhoneRectangleGadget),
						 &gPhoneX, &dummy);

	// Initialize the address list.
	lstP = ToolsGetFrmObjectPtr(frmP, DialListList);
	LstSetListChoices(lstP, 0, gPhonesCount);
	LstSetDrawFunction(lstP, PrvDialListDrawPhoneItem);

	// Set the top item to avoid flickering
	// Try to have the selected one in the middle
	visibleItems = LstGetVisibleItems(lstP);
	middle = ((visibleItems - 1) / 2);
	if ((gPhonesCount <= visibleItems) || (gSelectedIndex <= middle))
	{
		// top aligned
		topIndex = 0;
	}
	else if (gSelectedIndex >= (gPhonesCount - (visibleItems - middle)))
	{
		// bottom aligned
		topIndex = gPhonesCount - visibleItems;
	}
	else
	{
		// centered
		topIndex = gSelectedIndex - middle;
	}
	LstSetTopItem(lstP, topIndex);

	// initiate phone number field
	fldIndex = FrmGetObjectIndex(frmP, DialListNumberField);
	fldP = FrmGetObjectPtr(frmP, fldIndex);
	FldSetMaxChars(fldP, kMaxCharsPhoneNumber);
	PrvDialListUpdatePhoneNumber(fldP);
	FrmSetFocus(frmP, fldIndex);
}

/***********************************************************************
 *
 * FUNCTION:    PrvDialListInitData
 *
 * DESCRIPTION: This routine initializes the "Dial List" data of the 
 *              Address application.
 *
 * PARAMETERS:  none
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name		Date		Description
 *			----		----		-----------
 *			vivek		12/8/00	Initial Revision
 *
 ***********************************************************************/
void PrvDialListInitData( void )
{
	Err		err;
	Int16		fieldIndex;
	UInt16	recordIndex = gDialListData->recordIndex;
	UInt16	phoneIndex = gDialListData->phoneIndex;
	UInt16	lineIndex = gDialListData->lineIndex;
	// Get the current record
	err = AddrDBGetRecord(AddrDB, recordIndex, gAddrP, &gAddrH);
	if (!err)
	{

		// Check default phone index
		// If type is not a supported one, continue
		if (phoneIndex == kDialListShowInListPhoneIndex)
			phoneIndex = gAddrP->options.phones.displayPhoneForList;

		gAppInfoP = (AddrAppInfoType*)AddrDBAppInfoGetPtr(AddrDB);

		// Build the phone array
		// Splitting each phone field per line
		gPhonesCount = 0;
		for (fieldIndex = firstPhoneField; fieldIndex <= lastPhoneField; fieldIndex++)
		{
			Char* text = gAddrP->fields[fieldIndex];
			Char* next = text;
			Int16 length;
			Int16 phoneLineIndex = 0;

			if (text && ToolsIsPhoneIndexSupported(gAddrP, fieldIndex - firstPhoneField))
			{
				do
				{
					gPhones[gPhonesCount].number = text;
					
					// Check if a another line is available
					next = StrChr(text, chrLineFeed);
					
					// If a line feed is found
					if (next)
						length = next - text;
					else
						length = StrLen(text);
					
					// Check that the phone is a phone number (ie at least one phone character) 
					if (PrvDialListCanBePhoneNumber(text, length))
					{
						Int16 phoneLabelIndex;

						gPhones[gPhonesCount].number = text;
						gPhones[gPhonesCount].numberLen = length;

						phoneLabelIndex = GetPhoneLabel(gAddrP, fieldIndex); // 0 = Work... 7 = Mobile
						// gAppInfoP->fieldLabels stored name of fields in a strange way
						if (phoneLabelIndex < 5) // Work, Home, Fax, Other, Email are stored as phone1... phone5
							phoneLabelIndex += phone1;
						else	// Main, Pager and Mobile are stored after Note.
							phoneLabelIndex += note - 4;
						gPhones[gPhonesCount].label = gAppInfoP->fieldLabels[phoneLabelIndex];
						
						// Is is the selected one
						if ((phoneIndex == fieldIndex - firstPhoneField) && (phoneLineIndex == lineIndex))
							gSelectedIndex = gPhonesCount;
							
						gPhonesCount++;
						if (gPhonesCount == kMaxPhonesCount)
							break;
					}
					text = next + 1;
					phoneLineIndex++;
				}
				while (next);
			}
			if (gPhonesCount == kMaxPhonesCount)
				break;
		}
	}
}

/***********************************************************************
 *
 * FUNCTION:
 *	PrvDialListScroll
 *
 * DESCRIPTION:
 *	This routine scroll the list up or down (page per page)
 *
 * PARAMETERS
 *	direction	IN	direction to scroll (winUp or winDown)
 *
 * RETURNED:
 *	nothing
 *
 * REVISION HISTORY:
 *	Name	Date		Description
 *	----	----		-----------
 *	aro		06/19/00	Initial Revision
 *
 ***********************************************************************/
void PrvDialListScroll( WinDirectionType direction )
{
	ListType* lstP = ToolsGetFrmObjectPtr(FrmGetActiveForm(), DialListList);
	Int16 count = LstGetVisibleItems(lstP);
	LstScrollList(lstP, direction, count - 1);
}


/***********************************************************************
 *
 * FUNCTION:
 *	PrvDialListDrawPhoneItem
 *
 * DESCRIPTION:
 *	This routine draws a phone item line (label & number)
 *	It is called as a callback routine by the list object.
 *
 * PARAMETERS:
 *	itenNum		IN	index of the item to draw
 *	boundsP		IN	boundsP of rectangle to draw in
 *	itemsText	IN	data if any
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *	Name		Date		Description
 *	----		----		-----------
 *	aro			6/12/00		Initial Revision
 *
 ***********************************************************************/
void PrvDialListDrawPhoneItem( Int16 index, RectangleType *boundsP, Char **itemsText )
{
#pragma unused(itemsText)

	Char* number;
	Char* label;
	Int16 numberLen;
	Int16 labelLen;
	Int16 dummyLen;
	Coord labelMaxWidth;
	Coord dummyWidth;
	Boolean	fit;

	// retrieve the name and the label
	number = gPhones[index].number;
	numberLen = gPhones[index].numberLen;
	label = gPhones[index].label;
	labelLen = StrLen(label);
	dummyLen = labelLen;

	// Draw the label on the left (truncated if needed) + ":")
	labelMaxWidth = gPhoneX - boundsP->topLeft.x - kSpaceBetweenLabelAndNumber;
	dummyWidth = labelMaxWidth;
	FntCharsInWidth(label, &labelMaxWidth, &dummyLen, &fit);
	WinDrawTruncChars(label, labelLen, boundsP->topLeft.x, boundsP->topLeft.y, dummyWidth);
	WinDrawChars(":", 1, boundsP->topLeft.x + labelMaxWidth + 1, boundsP->topLeft.y);

	WinDrawTruncChars(number, numberLen, gPhoneX, boundsP->topLeft.y,
					  boundsP->extent.x + boundsP->topLeft.x - gPhoneX);
}


/***********************************************************************
 *
 * FUNCTION:
 *	PrvDialListUpdateAfterSelection
 *
 * DESCRIPTION:
 *	This routine update the number
 *	according to the new or current selection
 *	Set focus to the field
 *
 * PARAMETERS:
 *	frmP	IN	form
 *
 * RETURNED:
 *	nothing
 *
 * REVISION HISTORY:
 *	Name		Date		Description
 *	----		----		-----------
 *	aro			6/12/00		Initial Revision
 *
 ***********************************************************************/
void PrvDialListUpdateAfterSelection( FormType* frmP )
{
	FieldType* 	fldP;
	UInt16		fieldIndex;

	// Set the number in the field
	// Number is parse according to characters allowed
	fieldIndex = FrmGetObjectIndex(frmP, DialListNumberField);
	fldP = FrmGetObjectPtr(frmP, fieldIndex);
	PrvDialListUpdatePhoneNumber(fldP);
	FldDrawField(fldP);
	FrmSetFocus(frmP, fieldIndex);
}


/***********************************************************************
 *
 * FUNCTION:
 *	PrvDialListUpdatePhoneNumber
 *
 * DESCRIPTION:
 *	This routine update the number
 *	in the field according to current selection
 *	No drawn is made
 *
 * PARAMETERS:
 *	fldP	IN	field
 *
 * RETURNED:
 *	nothing
 *
 * REVISION HISTORY:
 *	Name		Date		Description
 *	----		----		-----------
 *	aro			6/12/00		Initial Revision
 *
 ***********************************************************************/
void PrvDialListUpdatePhoneNumber( FieldType* fldP )
{
	MemHandle	numberH;
	Char*		numberP;
	Int16		len;

	len = (Int16)FldGetMaxChars(fldP);

	len = min(len, gPhones[gSelectedIndex].numberLen);

	numberH = MemHandleNew(len + 1);
	if (!numberH)
		return;

	numberP = MemHandleLock(numberH);
	PrvDialListPhoneNumberFilter(numberP, &len, gPhones[gSelectedIndex].number, gPhones[gSelectedIndex].numberLen);
	numberP[len] = chrNull;
	MemHandleUnlock(numberH);
	MemHandleResize(numberH, len + 1);

	PrvDialListSetFieldHandle(fldP, numberH);
}


/***********************************************************************
 *
 * FUNCTION:
 *	PrvDialListFreeMemory
 *
 * DESCRIPTION:
 *	This routine frees memory allocated by the dialog
 *
 * PARAMETERS:
 *	none
 *
 * RETURNED:
 *	nothing
 *
 * REVISION HISTORY:
 *	Name		Date		Description
 *	----		----		-----------
 *	aro			6/12/00		Initial Revision
 *
 ***********************************************************************/
void PrvDialListFreeMemory( void )
{
	TraceOutput(TL(appErrorClass, "PrvDialListFreeMemory()"));

	if (gAppInfoP)
		MemPtrUnlock(gAppInfoP);
	if (gAddrH)
		MemHandleUnlock(gAddrH);

	if (gDisplayName)
		MemPtrFree(gDisplayName);
		
	if (gDialListData)
		MemPtrFree(gDialListData);

	gDialListData = 0;
}


/***********************************************************************
 *
 * FUNCTION:
 *	PrvDialListLeaveDialog
 *
 * DESCRIPTION:
 *	This routine leave the dialog
 *
 * PARAMETERS:
 *	none
 *
 * RETURNED:
 *	nothing
 *
 * REVISION HISTORY:
 *	Name		Date		Description
 *	----		----		-----------
 *	aro			6/12/00		Initial Revision
 *
 ***********************************************************************/
void PrvDialListLeaveDialog( void )
{
	TraceOutput(TL(appErrorClass, "PrvDialListLeaveDialog"));

	PrvDialListSetFieldHandle(ToolsGetObjectPtr(DialListNumberField), 0);
	PrvDialListFreeMemory();

	FrmReturnToForm(0);
	FrmUpdateForm(0, updateSelectCurrentRecord);
}


/***********************************************************************
 *
 * FUNCTION:
 *	PrvDialListDialSelected
 *
 * DESCRIPTION:
 *	This routine dial selected number
 *
 * PARAMETERS:
 *	none
 *
 * RETURNED:
 *	nothing
 *
 * REVISION HISTORY:
 *	Name		Date		Description
 *	----		----		-----------
 *	aro			6/12/00		Initial Revision
 *
 ***********************************************************************/
Boolean PrvDialListDialSelected( FormType* frmP )
{
	SysNotifyParamType param;
	HelperNotifyEventType details;
	HelperNotifyExecuteType execute;

	param.notifyType = sysNotifyHelperEvent;
	param.broadcaster = sysFileCAddress;
	param.notifyDetailsP = &details;
	param.handled = false;

	details.version = kHelperNotifyCurrentVersion;
	details.actionCode = kHelperNotifyActionCodeExecute;
	details.data.executeP = &execute;

	execute.serviceClassID = kHelperServiceClassIDVoiceDial;
	execute.helperAppID = 0;
	execute.dataP = FldGetTextPtr(ToolsGetFrmObjectPtr(frmP, DialListNumberField));
	execute.displayedName = gDisplayName;
	execute.detailsP = 0;
	execute.err = errNone;

	SysNotifyBroadcast(&param);

	// Check error code
	if (!param.handled)
		// Not handled so exit the list - Unexepcted error
		return true;
	else
	{
		TraceOutput(TL(appErrorClass, "Dial result: %hx", execute.err));
		return (execute.err == errNone);
	}
}

⌨️ 快捷键说明

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