📄 addrview.c
字号:
// Set the category label.
if (CurrentCategory == dmAllCategories)
{
DmRecordInfo (AddrDB, CurrentRecord, &attr, NULL, NULL);
category = attr & dmRecAttrCategoryMask;
}
else
category = CurrentCategory;
CategoryGetName (AddrDB, category, CategoryName);
index = FrmGetObjectIndex (frm, RecordCategoryLabel);
FrmSetCategoryLabel (frm, index, CategoryName);
// Allocate the record view lines
// But first free up RecordViewLines if it was previously allocated.
if (RecordViewLines)
{
MemHandleFree(MemPtrRecoverHandle(RecordViewLines));
RecordViewLines = 0;
}
RecordViewLinesH = MemHandleNew(sizeof(RecordViewLineType) * recordViewLinesMax);
ErrFatalDisplayIf (!RecordViewLinesH, "Out of memory");
RecordViewLines = MemHandleLock(RecordViewLinesH);
MemSet(RecordViewLines, sizeof(RecordViewLineType) * recordViewLinesMax, 0);
RecordViewLastLine = 0;
TopRecordViewLine = 0;
FrmGetFormBounds(frm, &r);
maxWidth = r.extent.x;
appInfoPtr = (AddrAppInfoPtr) AddrDBAppInfoGetPtr(AddrDB);
RecordLabelColumnWidth = ToolsGetLabelColumnWidth (appInfoPtr, AddrRecordFont);
// Get the record to display. recordViewRecordH may have data if
// we are redisplaying the record (custom fields changed).
if (recordViewRecordH)
MemHandleUnlock(recordViewRecordH);
AddrDBGetRecord (AddrDB, CurrentRecord, &recordViewRecord, &recordViewRecordH);
// Here we construct the recordViewLines info by laying out
// the record
#if USE_TEMPLATES
if (!PrvViewInitUsingTemplate(appInfoPtr, maxWidth))
#endif
{
curFont = FntSetFont (largeBoldFont);
if (recordViewRecord.fields[name] == NULL &&
recordViewRecord.fields[firstName] == NULL &&
recordViewRecord.fields[company] != NULL)
{
PrvViewAddField(company, &width, maxWidth, 0, 0, 0, 0);
PrvViewNewLine(&width);
}
else
{
if (recordViewRecord.fields[firstName] != NULL)
{
PrvViewAddField(firstName, &width, maxWidth, 0, 0, 0, 0);
// Separate the last name from the first name as long
// as they are together on the same line.
if (width > 0)
PrvViewAddSpaceForText (" ", &width);
}
PrvViewAddField(name, &width, maxWidth, 0, 0, 0, 0);
PrvViewNewLine(&width);
}
RecordViewFirstPlainLine = RecordViewLastLine;
FntSetFont (AddrRecordFont);
if (recordViewRecord.fields[title])
{
PrvViewAddField(title, &width, maxWidth, 0, 0, 0, 0);
PrvViewNewLine(&width);
}
if (recordViewRecord.fields[company] != NULL &&
(recordViewRecord.fields[name] != NULL ||
recordViewRecord.fields[firstName] != NULL))
{
PrvViewAddField(company, &width, maxWidth, 0, 0, 0, 0);
PrvViewNewLine(&width);
}
// If the line above isn't blank then add a blank line
if (RecordViewLastLine > 0 &&
RecordViewLines[RecordViewLastLine - 1].fieldNum != recordViewBlankLine)
{
PrvViewNewLine(&width);
}
// Layout the phone numbers. Start each number on its own line.
// Put the label first, followed by ": " and then the number
for (fieldIndex = firstPhoneField; fieldIndex <= lastPhoneField; fieldIndex++)
{
if (recordViewRecord.fields[fieldIndex])
{
phoneLabelNum = GetPhoneLabel(&recordViewRecord, fieldIndex);
PrvViewAddSpaceForText (appInfoPtr->fieldLabels[phoneLabelNum + ((phoneLabelNum < numPhoneLabelsStoredFirst) ? firstPhoneField : (addressFieldsCount - numPhoneLabelsStoredFirst))], &width);
PrvViewAddSpaceForText (": ", &width);
PrvViewPositionTextAt(&width, RecordLabelColumnWidth);
PrvViewAddField(fieldIndex, &width, maxWidth, RecordLabelColumnWidth, 0, 0, 0);
PrvViewNewLine(&width);
}
}
// If the line above isn't blank then add a blank line
if (RecordViewLastLine > 0 &&
RecordViewLines[RecordViewLastLine - 1].fieldNum != recordViewBlankLine)
{
PrvViewNewLine(&width);
}
// Now do the address information
if (recordViewRecord.fields[address])
{
PrvViewAddField(address, &width, maxWidth, 0, 0, 0, 0);
PrvViewNewLine(&width);
}
// We need to format the city, state, and zip code differently depending
// on which country it is. For now, assume that if the city comes first,
// we use the standard US formatting of [city, ][state ][zip]<cr>,
// otherwise we'll use the "int'l" format of [zip ][city]<cr>[state]<cr>.
// DOLATER kwk - A better way of handling this would be to use a formatting
// resource, which had N records, one for each line, where each record
// had M entries, one for each field, and each entry had a field id and
// suffix text.
i = 0;
fieldMapH = DmGetResource(fieldMapRscType, FieldMapID);
fieldMap = (const AddressFields*)MemHandleLock(fieldMapH);
while ((cityIndex == -1) || (zipIndex == -1))
{
if (fieldMap[i] == city)
{
cityIndex = i;
}
else if (fieldMap[i] == zipCode)
{
zipIndex = i;
}
i++;
}
MemHandleUnlock(fieldMapH);
DmReleaseResource(fieldMapH);
// Decide if we're formatting it US-style, or int'l-style
if (cityIndex < zipIndex)
{
if (recordViewRecord.fields[city])
{
PrvViewAddField(city, &width, maxWidth, 0, 0, 0, 0);
}
if (recordViewRecord.fields[state])
{
if (width > 0)
PrvViewAddSpaceForText (", ", &width);
PrvViewAddField(state, &width, maxWidth, 0, 0, 0, 0);
}
if (recordViewRecord.fields[zipCode])
{
if (width > 0)
PrvViewAddSpaceForText (" ", &width);
PrvViewAddField(zipCode, &width, maxWidth, 0, 0, 0, 0);
}
if (recordViewRecord.fields[city] ||
recordViewRecord.fields[state] ||
recordViewRecord.fields[zipCode])
{
PrvViewNewLine(&width);
}
}
else
{
if (recordViewRecord.fields[zipCode])
{
PrvViewAddField(zipCode, &width, maxWidth, 0, 0, 0, 0);
}
if (recordViewRecord.fields[city])
{
if (width > 0)
PrvViewAddSpaceForText (" ", &width);
PrvViewAddField(city, &width, maxWidth, 0, 0, 0, 0);
}
if (recordViewRecord.fields[zipCode] ||
recordViewRecord.fields[city])
{
PrvViewNewLine(&width);
}
if (recordViewRecord.fields[state])
{
PrvViewAddField(state, &width, maxWidth, 0, 0, 0, 0);
PrvViewNewLine(&width);
}
}
if (recordViewRecord.fields[country])
{
PrvViewAddField(country, &width, maxWidth, 0, 0, 0, 0);
PrvViewNewLine(&width);
}
// If the line above isn't blank then add a blank line
if (RecordViewLastLine > 0 &&
RecordViewLines[RecordViewLastLine - 1].fieldNum != recordViewBlankLine)
{
PrvViewNewLine(&width);
}
// Do the custom fields
for (i = custom1; i < addressFieldsCount - 1; i++)
{
if (recordViewRecord.fields[i])
{
PrvViewAddSpaceForText (appInfoPtr->fieldLabels[i], &width);
PrvViewAddSpaceForText (": ", &width);
PrvViewPositionTextAt(&width, RecordLabelColumnWidth);
PrvViewAddField(i, &width, maxWidth, RecordLabelColumnWidth, 0, 0, 0);
PrvViewNewLine(&width);
PrvViewNewLine(&width); // leave a blank line
}
}
// Show the note field.
if (recordViewRecord.fields[note])
{
PrvViewAddField(note, &width, maxWidth, 0, 0, 0, 0);
}
// Now remove trailing blank lines
while (RecordViewLastLine > 0 &&
RecordViewLines[RecordViewLastLine - 1].fieldNum == recordViewBlankLine)
{
RecordViewLastLine--;
}
FntSetFont (curFont);
}
MemPtrUnlock(appInfoPtr);
}
/***********************************************************************
*
* FUNCTION: PrvViewNewLine
*
* DESCRIPTION: Adds the next field at the start of a new line
*
* PARAMETERS: width - width already occupied on the line
*
* RETURNED: width is set
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 6/21/95 Initial Revision
*
***********************************************************************/
void PrvViewNewLine (UInt16 *width)
{
if (RecordViewLastLine >= recordViewLinesMax)
return;
if (*width == 0)
{
RecordViewLines[RecordViewLastLine].fieldNum = recordViewBlankLine;
RecordViewLines[RecordViewLastLine].x = 0;
RecordViewLines[RecordViewLastLine].length = 0;
RecordViewLines[RecordViewLastLine].offset = 0;
RecordViewLines[RecordViewLastLine].prefixStrID = 0;
RecordViewLines[RecordViewLastLine].suffixStrID = 0;
RecordViewLines[RecordViewLastLine].blockID = 0;
RecordViewLastLine++;
}
else
*width = 0;
}
/***********************************************************************
*
* FUNCTION: PrvViewAddSpaceForText
*
* DESCRIPTION: Adds space for text to the RecordViewLines info.
*
* PARAMETERS: string - Char * to text to leave space for
* width - width already occupied on the line
*
* RETURNED: width is increased by the width of the text
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 6/21/95 Initial Revision
*
***********************************************************************/
void PrvViewAddSpaceForText (const Char * const string, UInt16 *width)
{
*width += FntCharsWidth(string, StrLen(string));
}
/***********************************************************************
*
* FUNCTION: PrvViewPositionTextAt
*
* DESCRIPTION: Position the following text at the given position.
*
* PARAMETERS: position - position to indent to
* width - width already occupied on the line
*
* RETURNED: width is increased if the position is greater
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 8/2/95 Initial Revision
*
***********************************************************************/
void PrvViewPositionTextAt (UInt16 *width, const UInt16 position)
{
if (*width < position)
*width = position;
}
/***********************************************************************
*
* FUNCTION: PrvViewAddField
*
* DESCRIPTION: Adds a field to the RecordViewLines info.
*
* PARAMETERS: fieldNum - field to add
* width - width already occupied on the line
* maxWidth - can't add words past this width
* indentation - the amounnt of indentation wrapped lines of
* text should begin with (except the last)
*
* RETURNED: width is set to the width of the last line added
*
* HISTORY:
* 06/21/95 rsf Created by Roger Flores
* 10/25/99 kwk Fix sign extension w/calling TxtCharIsSpace
*
***********************************************************************/
void PrvViewAddField (const UInt16 fieldNum, UInt16 *widthPtr, const UInt16 maxWidth, const UInt16 indentation,
const UInt16 strID, const UInt16 fieldType, const UInt16 blockID)
{
WChar lastChar;
UInt16 width = *widthPtr;
UInt16 offset = 0;
UInt16 length;
Char *text;
Char string[kMaxPrefixSuffixLen];
if (fieldType != kViewRecordFieldNum)
text = ToolsGetStringResource (strID, string);
else
text = recordViewRecord.fields[fieldNum];
if ((text == NULL) ||
RecordViewLastLine >= recordViewLinesMax)
return;
// If we're past the maxWidth already then start at the beginning
// of the next line.
if (maxWidth <= width)
{
width = indentation;
}
while (RecordViewLastLine < recordViewLinesMax)
{
RecordViewLines[RecordViewLastLine].fieldNum = fieldNum;
RecordViewLines[RecordViewLastLine].offset = offset;
RecordViewLines[RecordViewLastLine].x = width;
RecordViewLines[RecordViewLastLine].suffixStrID = 0;
if (fieldType == kViewRecordSuffix)
RecordViewLines[RecordViewLastLine].suffixStrID = strID;
RecordViewLines[RecordViewLastLine].prefixStrID = 0;
if (fieldType == kViewRecordPrefix)
RecordViewLines[RecordViewLastLine].prefixStrID = strID;
RecordViewLines[RecordViewLastLine].blockID = blockID;
length = FldWordWrap (&text[offset], maxWidth - width);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -