📄 addrtools.c
字号:
if (!(addrP->fields[fieldIndex]))
return false;
switch (fieldIndex)
{
case phone1:
label = (AddressPhoneLabels)addrP->options.phones.phone1;
break;
case phone2:
label = (AddressPhoneLabels)addrP->options.phones.phone2;
break;
case phone3:
label = (AddressPhoneLabels)addrP->options.phones.phone3;
break;
case phone4:
label = (AddressPhoneLabels)addrP->options.phones.phone4;
break;
case phone5:
label = (AddressPhoneLabels)addrP->options.phones.phone5;
break;
default:
return false;
}
// Check whether this is a phone number and if so, whether it's one that's
// appropriate to be dialed.
switch (label)
{
// These are the phone numbers which are dialable.
case workLabel:
case homeLabel:
case otherLabel:
case mainLabel:
case pagerLabel:
case mobileLabel:
case faxLabel:
return true;
default:
return false;
}
}
/***********************************************************************
*
* FUNCTION:
* ToolsGetLineIndexAtOffset
*
* DESCRIPTION:
* This routine gets the line index of a string at a specified offset
*
* PARAMETERS:
* textP IN text to parse
* offset IN char offset
*
* RETURNED:
* index of the line
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* aro 6/27/00 Initial Revision
*
***********************************************************************/
UInt16 ToolsGetLineIndexAtOffset( Char* textP, UInt16 offset )
{
Char* nextP;
UInt16 lineIndex = 0;
while (offset)
{
nextP = StrChr(textP, chrLineFeed);
if (nextP)
{
UInt16 diff = nextP - textP;
if (offset <= diff)
break;
else
{
offset -= (diff + 1);
textP = nextP + 1;
lineIndex++;
}
}
else
break;
}
return lineIndex;
}
/***********************************************************************
*
* FUNCTION:
* ToolsGetPhoneLabelWidth
*
* DESCRIPTION:
* This routine returns the width of the phone labels. It first looks
* for a string in the application to calculate the width. If the string
* is not present, it uses 'W' as the maximum width character for a phone
* label.
*
* PARAMETERS:
* none
*
* RETURNED:
* width for a phone label.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* vsm 10/08/2002 Initial Revision
*
***********************************************************************/
Int16 ToolsGetPhoneLabelWidth( void )
{
MemHandle strHdl;
Int16 width;
strHdl = DmGetResource(strRsc, PhoneLabelMaxCharWidthStr);
if (strHdl)
{
Char* strP;
strP = (Char*)MemHandleLock(strHdl);
width = FntCharsWidth(strP, StrLen(strP));
MemHandleUnlock(strHdl);
DmReleaseResource(strHdl);
}
else
width = FntCharWidth('W');
return width;
}
/***********************************************************************
*
* FUNCTION: ToolsMatchAlternateEncoding
*
* DESCRIPTION: Determines whether the text buffer passed in contains
* characters that match the alternate encoding that the application
* may have specified.
* NOTE : This is a very simplistic test. The right way to do this
* would be to set up a list of alternate encodings since
* a string could map for example to USAscii, 8859_1 or even CP1252.
*
*
* PARAMETERS: pointer to text buffer
* altEncoding
*
* RETURNED: true - if the string is encoded in the "alternate" encoding.
* false - otherwise.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* vsm 2002-10-09 Initial Revision
*
***********************************************************************/
Boolean ToolsMatchAlternateEncoding(Char *textP, CharEncodingType altEncoding)
{
Boolean retVal = false;
if (textP && *textP)
{
if (TxtStrEncoding(textP) == altEncoding)
retVal = true;
}
return retVal;
}
/***********************************************************************
*
* FUNCTION: ToolsGetDisplayNameLayout
*
* DESCRIPTION: This function takes in two strings and returns in outFieldMap
* the layout info that can be used to display the two strings
* along with the separator to be used between the two strings.
*
* PARAMETERS: str1, str2 -> strings to use while determining the layout.
* outFieldMap -> pointer to a NameLayoutFieldMapType buffer
* which will get filled in by this function.
*
*
* RETURNED: true - if there is a NLFM resource to use
* false - otherwise.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* vsm 2002-12-05 Initial Revision (moved code from AddrDialList).
*
***********************************************************************/
Boolean ToolsGetDisplayNameLayout(Char* str1, Char* str2, NameLayoutFieldMapType *outFieldMap)
{
MemHandle resH;
UInt16 nameLayoutID;
CharEncodingType altSeparatorEncoding = charEncodingUnknown;
NameLayoutFieldMapType* nameFieldMapP;
// First check if there is an alternate encoding 'tint' resource; if it does then
// it indicates that NLFM resources will also be present. Otherwise we are dealing
// with legacy EFIGS code that doesn't have the resources.
resH = DmGetResource(constantRscType, FieldSeparatorAltEncodingConst);
ErrNonFatalDisplayIf(!resH, "We are missing the tint 1000 FieldSeparatorAltEncodingConst resource.");
if (!resH)
return false;
altSeparatorEncoding = (CharEncodingType)*(UInt32 *) MemHandleLock (resH);
MemHandleUnlock (resH);
DmReleaseResource (resH);
if (altSeparatorEncoding == charEncodingUnknown)
return false;
nameLayoutID = NameLayoutFieldMapID;
// If both name1 or name2 are encoded in the alternate encoding, then use the alternate layout.
if ((ToolsMatchAlternateEncoding(str1, altSeparatorEncoding))
&& (ToolsMatchAlternateEncoding(str2, altSeparatorEncoding)))
nameLayoutID = NameAltLayoutFieldMapID;
resH = DmGetResource(NameLayoutFieldMapRscType, nameLayoutID);
ErrNonFatalDisplayIf(!resH, "No name layout field map resource found");
nameFieldMapP = (NameLayoutFieldMapType*) MemHandleLock (resH);
*outFieldMap = *nameFieldMapP;
MemHandleUnlock(resH);
DmReleaseResource(resH);
return true;
}
/***********************************************************************
*
* FUNCTION: ToolsSetupSeparators
*
* DESCRIPTION: This function setups the the field separator string and
* length based on the contents of the two text buffers passed
* in. If either of the buffers has characters that fall into
* the non-ascii range we use the alternate field separator
* mappings.
*
*
* PARAMETERS: name1 - the first text buffer
* name2 - the second text buffer
* fieldSeparatorStrP - the field Separator Str will be returned in this pointer
* fieldSeparatorLen - the field separator len is returned in this pointer
* name1HasPriority - flag specifying whether name is the first field or whether
* company is the first field.
*
*
* RETURNED: the fieldSeparatorLen, and fieldSeparatorStrP
*
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* vsm 2002-10-09 Initial Revision
*
***********************************************************************/
void ToolsSetupSeparators(Char* name1, Char* name2, Char* fieldSeparatorStrP,
Int16 *fieldSeparatorLen, Boolean name1HasPriority)
{
MemHandle resH;
CharEncodingType altSeparatorEncoding = charEncodingUnknown;
// If we aren't set up with name1HasPriority we are displaying the company name and in that case
// we want the company separator - which in this case is the same as the std "fieldSeparatorString"
// viz. the comma.
// DOLATER - We need a sortBycompany separator.
if (!name1HasPriority)
{
StrCopy (fieldSeparatorStrP ,fieldSeparatorString );
*fieldSeparatorLen = fieldSeparatorLength;
return;
}
// Check the alternate separator usage encoding.
resH = DmGetResource(constantRscType, FieldSeparatorAltEncodingConst);
ErrNonFatalDisplayIf(!resH, "We are missing the tint 1000 FieldSeparatorAltEncodingConst resource.");
if (resH)
{
altSeparatorEncoding = (CharEncodingType)*(UInt32 *) MemHandleLock (resH);
MemHandleUnlock (resH);
DmReleaseResource (resH);
// Locales that do not need an alternate separator encoding (e.g. Latin locales) use the value
// charEncodingUnknown for FieldSeparatorAltEncodingConst and in that case we fall through to using
// the defaults in PrvToolsGetSeparatorString().
if (altSeparatorEncoding != charEncodingUnknown)
{
// If both name1 or name2 are encoded in the alternate encoding, then use the alternate separators.
if ((ToolsMatchAlternateEncoding(name1, altSeparatorEncoding))
&& (ToolsMatchAlternateEncoding(name2, altSeparatorEncoding)))
{
if (!PrvToolsGetSeparatorString(ListViewAltFieldSeparatorStr, fieldSeparatorStrP, fieldSeparatorLen))
{
StrCopy (fieldSeparatorStrP, fieldSeparatorString);
*fieldSeparatorLen = fieldSeparatorLength;
}
return;
}
}
}
// So we weren't doing a sortByCompany and our data didn't meet the alternate encoding criteria.
// Therefore just use the locale specific separator.
if (!PrvToolsGetSeparatorString(ListViewFieldSeparatorStr, fieldSeparatorStrP, fieldSeparatorLen))
{
StrCopy (fieldSeparatorStrP, fieldSeparatorString);
*fieldSeparatorLen = fieldSeparatorLength;
}
}
#pragma mark -
/***********************************************************************
*
* FUNCTION: PrvToolsPhoneIsANumber
*
* DESCRIPTION: Determines whether the phone field contains a number or a
* string using the following heuristic: if the string contains
* more numeric characters than non-numeric, it is a number.
*
* PARAMETERS: phone - pointer to phone string
*
* RETURNED: true if the string is a number.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* jeff 4/15/99 Initial Revision
*
***********************************************************************/
static Boolean PrvToolsPhoneIsANumber( Char* phone )
{
UInt16 digitCount = 0;
UInt16 charCount = 0;
UInt32 byteLength = 0;
WChar ch;
byteLength += TxtGetNextChar( phone, byteLength, &ch );
while ( ch != 0 )
{
charCount++;
if ( TxtCharIsDigit( ch ) ) digitCount++;
byteLength += TxtGetNextChar( phone, byteLength, &ch );
}
return ( digitCount > ( charCount / 2 ) );
}
/***********************************************************************
*
* FUNCTION: PrvToolsGetListFieldsLayout
*
* DESCRIPTION: Get the field order for displaying an address in a list
* style (in the list view and lookup).
*
* PARAMETERS: pointer to buffer to fill up the field order
* flag indicating whether the view is sorted by company name
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* vsm 2002-10-08 Initial Revision
*
***********************************************************************/
static void PrvToolsGetListFieldsLayout(ListLayoutFieldMapType * layoutMapP, Boolean sortByCompany)
{
UInt16 resID = ListLayoutFieldMapSortNameID; // Std All fields Ascii layout
MemHandle layoutHdl;
if (sortByCompany)
resID = ListLayoutFieldMapSortCompanyID; // Std all fields Ascii layout
// Next look to see if there is a resource that will give us this mapping.
layoutHdl = DmGetResource(ListLayoutFieldMapRscType, resID);
if (layoutHdl)
{
ListLayoutFieldMapType * mapP;
mapP = (ListLayoutFieldMapType *)MemHandleLock(layoutHdl);
MemMove(layoutMapP, mapP, sizeof(ListLayoutFieldMapType));
MemHandleUnlock(layoutHdl);
DmReleaseResource(layoutHdl);
}
else
{
// If there is no resource then just default to the standard Latin formatting.
if (sortByCompany)
{
layoutMapP->fieldNameChoiceList[0] = company;
layoutMapP->fieldNameChoiceList[1] = name;
layoutMapP->fieldNameChoiceList[2] = firstName;
layoutMapP->fieldNameChoiceList[3] = addressFieldsCount;
layoutMapP->altFieldNameChoiceList[0] = addressFieldsCount; // No alternate display fields.
}
else
{
layoutMapP->fieldNameChoiceList[0] = name;
layoutMapP->fieldNameChoiceList[1] = firstName;
layoutMapP->fieldNameChoiceList[2] = addressFieldsCount;
layoutMapP->fieldNameChoiceList[3] = addressFieldsCount;
layoutMapP->altFieldNameChoiceList[0] = company; // If we don't have name or firstname
// then try company.
}
layoutMapP->altFieldNameChoiceList[1] = addressFieldsCount; // No alternate display fields.
layoutMapP->altFieldNameChoiceList[2] = addressFieldsCount; // No alternate display fields.
layoutMapP->altFieldNameChoiceList[3] = addressFieldsCount; // No alternate display fields.
}
}
/***********************************************************************
*
* FUNCTION: PrvToolsGetSeparatorString
*
* DESCRIPTION: Copy the contents of a string resource if it exists - don't
* complain if it doesn't.
*
* PARAMETERS: resource Id of the string to load
* pointer to text buffer to copy the contents into.
* pointer to length field to be returned.
*
* RETURNED: true - if the string was found
* false - otherwise.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* vsm 2002-10-09 Initial Revision
*
***********************************************************************/
static Boolean PrvToolsGetSeparatorString(UInt16 resID, Char* destStringP, Int16 *len)
{
MemHandle strH;
Char* strP;
strH = DmGetResource(strRsc, resID);
if (strH)
{
strP = (Char *) MemHandleLock (strH);
*len = StrLen(strP);
ErrNonFatalDisplayIf(*len > kMaxSeparatorStrLen, "Field Separator too long.");
if (*len)
StrCopy (destStringP, strP);
else
destStringP[0] = '\0';
MemHandleUnlock (strH);
DmReleaseResource (strH);
return true;
}
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -