📄 addresslookup.c
字号:
* PARAMETERS: vars - variables used by the lookup code.
* record - record to draw
* field - phone to draw
* bounds - bounds of the draw region
* phoneLabelLetters - the first letter of each phone label
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 6/21/95 Initial Revision
* vivek 12/3/02 Fix bug with passing in NULL as parameters to
* ToolsDetermineRecordName for the unnamed
* string.
***********************************************************************/
void PrvLookupDrawRecordFields(LookupVariablesPtr vars, AddrDBRecordPtr record, Int16 field, RectanglePtr bounds, WChar * phoneLabelLetters)
{
Char * name1;
Char * name2;
Char * field1;
Char * field2;
Int16 x;
Int16 y;
Int16 field1Length;
Int16 field2Length;
Int16 field1Width;
Int16 field2Width;
Int16 horizontalSpace;
UInt16 phoneLabel;
Int16 fieldSeparatorWidth;
Int16 shortenedFieldWidth;
UInt16 field1Num;
UInt16 field2Num;
Int16 name1Length;
Int16 name2Length;
Int16 name1Width;
Int16 name2Width;
Boolean ignored;
Boolean everythingFits;
Boolean name1HasPriority = true;
UInt8 phoneLabelWidth;
Char *unnamedRecordStringPtr = NULL;
MemHandle unnamedRecordStringH = NULL;
x = bounds->topLeft.x;
y = bounds->topLeft.y;
phoneLabelWidth = ToolsGetPhoneLabelWidth() - 1; // remove the blank trailing column
// phoneLabelWidth = FntCharWidth('W') - 1;
TraceOutput(TL(appErrorClass,"PrvLookupDrawRecordFields() - *"));
// Do we need to figure out the person's name?
if (vars->params->field1 == addrLookupSortField || vars->params->field2 == addrLookupSortField)
name1HasPriority = ToolsDetermineRecordName (record, &shortenedFieldWidth, &fieldSeparatorWidth, vars->sortByCompany,
&name1, &name1Length, &name1Width, &name2, &name2Length, &name2Width,
&unnamedRecordStringPtr, &unnamedRecordStringH, bounds->extent.x);
TraceOutput(TL(appErrorClass,"PrvLookupDrawRecordFields() - **"));
// Handle the first field to display
field1Num = vars->params->field1;
if (field1Num == addrLookupSortField)
field1Width = name1Width + (name2 ? fieldSeparatorWidth : 0) + name2Width;
else if (field1Num == addrLookupNoField)
{
field1Length = 0;
field1Width = 0;
}
else
{
// Map from the lookup field requested to the Address's format
if (IsPhoneLookupField(field1Num))
{
field1 = record->fields[field];
}
else if (field1Num == addrLookupListPhone)
{
field1 = record->fields[phone1 + record->options.phones.displayPhoneForList];
}
else
{
field1 = record->fields[vars->lookupFieldMap[field1Num]];
}
if (field1)
{
// Only show text from the first line in the field
field1Width = bounds->extent.x;
field1Length = field1Width; // more characters than we can expect
FntCharsInWidth (field1, &field1Width, &field1Length, &ignored);//lint !e64
// Leave room for a letter to indicate which phone is being displayed.
if (field1Num == addrLookupListPhone)
field1Width += phoneLabelWidth + 1;
}
else
{
field1Length = 0;
field1Width = 0;
}
}
// Handle the second field to display
field2Num = vars->params->field2;
if (field2Num == addrLookupSortField)
{
// This is the width of the name before any truncation.
field2Width = name1Width + (name2 ? fieldSeparatorWidth : 0) + name2Width;
}
else if (field2Num == addrLookupNoField)
{
field2Length = 0;
field2Width = 0;
}
else
{
// Map from the lookup field requested to the Address's format
if (IsPhoneLookupField(field2Num))
{
field2 = record->fields[field];
}
else if (field2Num == addrLookupListPhone)
{
field2 = record->fields[phone1 + record->options.phones.displayPhoneForList];
}
else
{
field2 = record->fields[vars->lookupFieldMap[field2Num]];
}
if (field2)
{
// Only show text from the first line in the field
field2Width = bounds->extent.x;
field2Length = field2Width; // more characters than we can expect
FntCharsInWidth (field2, &field2Width, &field2Length, &ignored);//lint !e64
// Leave room for a letter to indicate which phone is being displayed.
if (vars->params->field2 == addrLookupListPhone)
field2Width += phoneLabelWidth + 1;
}
else
{
field2Length = 0;
field2Width = 0;
}
}
// Now check if everything can display without any truncation.
everythingFits = bounds->extent.x >= field1Width +
((field1Width && field2Width) ? spaceBetweenNamesAndPhoneNumbers : 0) +
field2Width;
/* if (bounds->extent.x >= name1Width + (name2 ? fieldSeparatorWidth : 0) +
name2Width + (phone ? spaceBetweenNamesAndPhoneNumbers : 0) + phoneWidth)
*/ {
}
// Find out how much room the left side can use
if (everythingFits || field2Num == addrLookupNoField)
horizontalSpace = bounds->extent.x;
else
{
horizontalSpace = bounds->extent.x - spaceBetweenNamesAndPhoneNumbers;
// This allows the left side to use space on the right side if the
// right side is small enough.
horizontalSpace -= min(horizontalSpace / 2, field2Width);
}
x = bounds->topLeft.x;
// Now draw the left side.
if (vars->params->field1 == addrLookupSortField)
{
ToolsDrawRecordName (name1, name1Length, name1Width, name2, name2Length, name2Width,
horizontalSpace, &x, y, shortenedFieldWidth, fieldSeparatorWidth, false,
name1HasPriority || !vars->sortByCompany, false);
// Remember how much width was actually used for field1
field1Width = x - bounds->topLeft.x;
}
else if (vars->params->field1 == addrLookupListPhone)
{
if (field1Width > horizontalSpace)
{
everythingFits = false;
field1Width = horizontalSpace - phoneLabelWidth - 1 - shortenedFieldWidth;
FntCharsInWidth(field1, &field1Width, &field1Length, &ignored);
}
else
{
everythingFits = true;
field1Width -= phoneLabelWidth + 1;
}
x = bounds->topLeft.x;
if (!everythingFits)
x -= shortenedFieldWidth;
WinDrawChars(field1, field1Length, x, y);
x = bounds->topLeft.x + field1Width;
if (!everythingFits)
{
WinDrawChars(shortenedFieldString, shortenedFieldLength,
x, y);
x += shortenedFieldWidth;
}
// Draw the first letter of the phone field label
phoneLabel = GetPhoneLabel(record, firstPhoneField +
record->options.phones.displayPhoneForList);
WinDrawChar (phoneLabelLetters[phoneLabel],
x + ((phoneLabelWidth - (FntWCharWidth(phoneLabelLetters[phoneLabel]) - 1)) >> 1), //lint !e702
y);
// Remember how much width was actually used for field1
field1Width = x + phoneLabelWidth - bounds->topLeft.x;
}
else if (vars->params->field1 != addrLookupNoField)
{
if (field1Width > horizontalSpace)
{
everythingFits = false;
field1Width = horizontalSpace - shortenedFieldWidth;
FntCharsInWidth(field1, &field1Width, &field1Length, &ignored);//lint !e64
}
else
{
everythingFits = true;
}
x = bounds->topLeft.x;
WinDrawChars(field1, field1Length, x, y);
x += field1Width;
if (!everythingFits)
{
WinDrawChars(shortenedFieldString, shortenedFieldLength, x, y);
x += shortenedFieldWidth;
}
// Remember how much width was actually used for field1
field1Width = x - bounds->topLeft.x;
}
// Find out how much room the right side can use
horizontalSpace = bounds->extent.x - field1Width - spaceBetweenNamesAndPhoneNumbers;
x = bounds->topLeft.x + bounds->extent.x - field1Width;
// Now draw the right side.
if (vars->params->field2 == addrLookupSortField)
{
ToolsDrawRecordName (name1, name1Length, name1Width, name2, name2Length, name2Width,
horizontalSpace, &x, y, shortenedFieldWidth, fieldSeparatorWidth, false,
name1HasPriority || !vars->sortByCompany, false);
}
else if (vars->params->field2 == addrLookupListPhone)
{
if (field2Width > horizontalSpace)
{
everythingFits = false;
field2Width = horizontalSpace - phoneLabelWidth - 1 - shortenedFieldWidth;
FntCharsInWidth(field2, &field2Width, &field2Length, &ignored);//lint !e64
}
else
{
everythingFits = true;
field2Width -= phoneLabelWidth + 1;
}
x = bounds->topLeft.x + (bounds->extent.x - 1) - field2Width - phoneLabelWidth - 1;
if (!everythingFits)
x -= shortenedFieldWidth;
WinDrawChars(field2, field2Length, x, y);
if (!everythingFits)
{
WinDrawChars(shortenedFieldString, shortenedFieldLength,
bounds->topLeft.x + (bounds->extent.x - 1) - shortenedFieldWidth -
phoneLabelWidth - 1, y);
}
// Draw the first letter of the phone field label
phoneLabel = GetPhoneLabel(record, firstPhoneField +
record->options.phones.displayPhoneForList);
WinDrawChar (phoneLabelLetters[phoneLabel],
bounds->topLeft.x + (bounds->extent.x - 1) - phoneLabelWidth +
((phoneLabelWidth - (FntWCharWidth(phoneLabelLetters[phoneLabel]) - 1)) >> 1), //lint !e702
y);
}
else if (vars->params->field2 != addrLookupNoField)
{
if (field2Width > horizontalSpace)
{
everythingFits = false;
field2Width = horizontalSpace - shortenedFieldWidth;
FntCharsInWidth(field2, &field2Width, &field2Length, &ignored);//lint !e64
}
else
{
everythingFits = true;
}
x = bounds->topLeft.x + bounds->extent.x - field2Width;
if (!everythingFits)
x -= shortenedFieldWidth;
WinDrawChars(field2, field2Length, x, y);
if (!everythingFits)
WinDrawChars(shortenedFieldString, shortenedFieldLength, bounds->topLeft.x + bounds->extent.x - shortenedFieldWidth, y);
}
if ( unnamedRecordStringPtr != NULL )
MemPtrUnlock(unnamedRecordStringPtr);
if ( unnamedRecordStringH != NULL )
DmReleaseResource(unnamedRecordStringH);
}
/***********************************************************************
*
* FUNCTION: PrvLookupViewDrawRecord
*
* 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 7/9/96 Initial Revision
*
***********************************************************************/
void PrvLookupViewDrawRecord (void * table, Int16 row, Int16 column, RectanglePtr bounds)
{
UInt16 recordNum;
Int16 fieldNum;
Err error;
AddrDBRecordType record;
MemHandle recordH;
LookupVariablesPtr vars;
TraceOutput(TL(appErrorClass, "PrvLookupViewDrawRecord() - table = %lu, row = %hu, column = %hu",table, row, column));
// 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);
vars = (LookupVariablesPtr) TblGetRowData(table, row);
error = AddrDBGetRecord (vars->dbP, recordNum, &record, &recordH);
ErrNonFatalDisplayIf ((error), "Record not found");
if (error) return;
fieldNum = TblGetItemInt(table, row, column);
FntSetFont (stdFont);
PrvLookupDrawRecordFields (vars, &record, fieldNum, bounds, vars->phoneLabelLetters);
MemHandleUnlock(recordH);
}
/***********************************************************************
*
* FUNCTION: PrvLookupViewUpdateScrollButtons
*
* DESCRIPTION: Show or hide the list view scroll buttons.
*
* PARAMETERS: vars - variables used by the lookup code.
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* Roger 7/9/96 Initial Revision
*
***********************************************************************/
void PrvLookupViewUpdateScrollButtons (LookupVariablesPtr vars)
{
Int16 row;
UInt16 upIndex;
UInt16 downIndex;
UInt16 recordNum;
Int16 phoneNum;
Boolean scrollableUp;
Boolean scrollableDown;
TablePtr table;
// Update the buttons that scroll the list.
//
// If the first record displayed is not the fist record in the category,
// enable the up scroller.
recordNum = vars->topVisibleRecord;
phoneNum = vars->topVisibleRecordPhone;
scrollableUp = AddrDBLookupSeekRecord (vars->dbP, &recordNum, &phoneNum, 1, dmSeekBackward,
vars->params->field1, vars->params->field2, vars->lookupFieldMap);
// Find the record in the last row of the table
table = ToolsGetObjectPtr (LookupTable);
for (row = TblGetNumberOfRows (table) - 1; row >= 0; row--)
{
// Make the row usable.
if (TblRowUsable (table, row))
{
recordNum = TblGetRowID (table, row);
phoneNum = TblGetItemInt (table, row, 0);
break;
}
}
// If the last record displayed is not the last record in the category,
// enable the down scroller.
scrollableDown = AddrDBLookupSeekRecord (vars->dbP, &recordNum, &phoneNum, 1, dmSeekForward,
vars->params->field1, vars->params->field2, vars->lookupFieldMap);
// Update the scroll button.
upIndex = FrmGetObjectIndex (vars->frm, LookupUpButton);
downIndex = FrmGetObjectIndex (vars->frm, LookupDownButton);
FrmUpdateScrollers (vars->frm, upIndex, downIndex, scrollableUp, scrollableDown);
}
/***********************************************************************
*
* FUNCTION: PrvLookupLoadTable
*
* DESCRIPTION: This routine loads address book database records into
* the lookup view form. Note that the phone field may
* be set to the first or last field if it isn't field1 or
* field2 and the table is loaded either forward or backward.
* So ignore it if phone are not being displayed.
*
* PARAMETERS: vars - variables used by the lookup code.
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* Roger 7/9/96 Initial Revision
*
***********************************************************************/
void PrvLookupLoadTable (LookupVariablesPtr vars)
{
UInt16 row;
UInt16 numRows;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -