📄 addresslookup.c
字号:
UInt16 recordNum;
Int16 phoneNum;
TablePtr table;
Boolean searchPhones;
// For each row in the table, store the record number as the row id.
table = ToolsGetObjectPtr (LookupTable);
// Make sure we haven't scrolled too far down the list of records
// leaving blank lines in the table.
// Try going forward to the last record that should be visible
numRows = TblGetNumberOfRows (table);
recordNum = vars->topVisibleRecord;
phoneNum = vars->topVisibleRecordPhone;
if (!AddrDBLookupSeekRecord (vars->dbP, &recordNum, &phoneNum, numRows - 1, dmSeekForward,
vars->params->field1, vars->params->field2, vars->lookupFieldMap))
{
// We have at least one line without a record. Fix it.
// Try going backwards one page from the last record
vars->topVisibleRecord = dmMaxRecordIndex;
vars->topVisibleRecordPhone = numPhoneFields - 1;
if (!AddrDBLookupSeekRecord (vars->dbP, &vars->topVisibleRecord, &vars->topVisibleRecordPhone,
numRows - 1, dmSeekBackward, vars->params->field1, vars->params->field2,
vars->lookupFieldMap))
{
// Not enough records to fill one page. Start with the first record
vars->topVisibleRecord = 0;
vars->topVisibleRecordPhone = 0;
AddrDBLookupSeekRecord (vars->dbP, &vars->topVisibleRecord, &vars->topVisibleRecordPhone,
0, dmSeekForward, vars->params->field1, vars->params->field2,
vars->lookupFieldMap);
}
}
numRows = TblGetNumberOfRows (table);
recordNum = vars->topVisibleRecord;
phoneNum = vars->topVisibleRecordPhone;
searchPhones = IsPhoneLookupField(vars->params->field1) ||
IsPhoneLookupField(vars->params->field2);
for (row = 0; row < numRows; row++)
{
if ( ! AddrDBLookupSeekRecord (vars->dbP, &recordNum, &phoneNum, 0, dmSeekForward,
vars->params->field1, vars->params->field2, vars->lookupFieldMap))
break;
// Make the row usable.
TblSetRowUsable (table, row, true);
// Mark the row invalid so that it will draw when we call the
// draw routine.
TblMarkRowInvalid (table, row);
// Store the record number as the row id.
TblSetRowID (table, row, recordNum);
// Store a pointer to vars for the callback. Ideally the table would
// have one copy of this information but it doesn't so we keep
// a pointer to vars in every row.
TblSetRowData(table, row, (UInt32) vars);
// Store the field used for a phone in the item int.
// We need to do this because some records have multiple
// occurances when they have multiple identical phone types
// (i.e. two email address). The type is AddressField.
// Remember that we allow only one of the two fields to be
// a phone field.
TblSetItemInt (table, row, 0, firstPhoneField + phoneNum);
if (searchPhones)
{
phoneNum++;
if (phoneNum >= numPhoneFields)
{
phoneNum = 0;
recordNum++;
}
}
else
recordNum++;
}
// Hide the item that don't have any data.
while (row < numRows)
{
TblSetRowUsable (table, row, false);
row++;
}
TblUnhighlightSelection(table);
PrvLookupViewUpdateScrollButtons(vars);
}
/***********************************************************************
*
* FUNCTION: PrvLookupViewScroll
*
* DESCRIPTION: This routine scrolls the list of names and phone numbers
* in the direction specified.
*
* PARAMETERS: vars - variables used by the lookup code.
* direction - up or dowm
* oneLine - if true the list is scroll by a single line,
* if false the list is scroll by a full screen.
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* Roger 7/9/96 Initial Revision
*
***********************************************************************/
void PrvLookupViewScroll (LookupVariablesPtr vars, WinDirectionType direction, Boolean oneLine)
{
TablePtr table;
UInt16 rowsInTable;
UInt16 newTopVisibleRecord;
Int16 newTopVisibleRecordPhone;
table = ToolsGetObjectPtr (LookupTable);
rowsInTable = TblGetNumberOfRows (table);
newTopVisibleRecord = vars->topVisibleRecord;
newTopVisibleRecordPhone = vars->topVisibleRecordPhone;
// Scroll the table down.
if (direction == winDown)
{
// Scroll down a single line. If we can't scroll down a line
// then the scroll down arrow would not have been displayed.
if (oneLine)
{
AddrDBLookupSeekRecord (vars->dbP, &newTopVisibleRecord, &newTopVisibleRecordPhone,
1, dmSeekForward, vars->params->field1, vars->params->field2, vars->lookupFieldMap);
ErrNonFatalDisplayIf (DmGetLastErr(), "Error scrolling");
}
// Scroll down a page (less one row).
else
{
// Try going forward one page
if (!AddrDBLookupSeekRecord (vars->dbP, &newTopVisibleRecord, &newTopVisibleRecordPhone,
rowsInTable - 1, dmSeekForward, vars->params->field1, vars->params->field2,
vars->lookupFieldMap))
{
// Try going backwards one page from the last record
newTopVisibleRecord = dmMaxRecordIndex;
newTopVisibleRecordPhone = numPhoneFields - 1;
if (!AddrDBLookupSeekRecord (vars->dbP, &newTopVisibleRecord, &newTopVisibleRecordPhone,
rowsInTable - 1, dmSeekBackward, vars->params->field1,
vars->params->field2, vars->lookupFieldMap))
{
// Not enough records to fill one page. Start with the first record
newTopVisibleRecord = 0;
newTopVisibleRecordPhone = 0;
AddrDBLookupSeekRecord (vars->dbP, &newTopVisibleRecord, &newTopVisibleRecordPhone,
0, dmSeekForward, vars->params->field1, vars->params->field2,
vars->lookupFieldMap);
}
}
}
}
// Scroll the table up.
else
{
// Scroll up a single line
if (oneLine)
{
AddrDBLookupSeekRecord (vars->dbP, &newTopVisibleRecord, &newTopVisibleRecordPhone, 1,
dmSeekBackward, vars->params->field1, vars->params->field2, vars->lookupFieldMap);
ErrNonFatalDisplayIf (DmGetLastErr(), "Error scrolling");
}
// Scroll up a page (less one row).
else
{
if (!AddrDBLookupSeekRecord (vars->dbP, &newTopVisibleRecord, &newTopVisibleRecordPhone,
rowsInTable - 1, dmSeekBackward, vars->params->field1, vars->params->field2,
vars->lookupFieldMap))
{
// Not enough records to fill one page. Start with the first record
newTopVisibleRecord = 0;
newTopVisibleRecordPhone = 0;
AddrDBLookupSeekRecord (vars->dbP, &newTopVisibleRecord, &newTopVisibleRecordPhone,
0, dmSeekForward, vars->params->field1, vars->params->field2,
vars->lookupFieldMap);
}
}
}
// Avoid redraw if no change
if (vars->topVisibleRecord != newTopVisibleRecord ||
vars->topVisibleRecordPhone != newTopVisibleRecordPhone)
{
vars->topVisibleRecord = newTopVisibleRecord;
vars->topVisibleRecordPhone = newTopVisibleRecordPhone;
PrvLookupLoadTable(vars);
TblRedrawTable(table);
}
}
/***********************************************************************
*
* FUNCTION: PrvLookupViewSelectRecord
*
* DESCRIPTION: Selects (highlights) a record on the table, scrolling
* the record if neccessary. Also sets the CurrentRecord.
*
* PARAMETERS: vars - variables used by the lookup code.
* recordNum - record to select
* phoneNum - phone in record to select
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* Roger 7/9/96 Initial Revision
*
***********************************************************************/
void PrvLookupViewSelectRecord (LookupVariablesPtr vars, UInt16 recordNum, UInt16 phoneNum)
{
Int16 row, column;
TablePtr tableP;
UInt16 attr;
Boolean recordFound;
Boolean searchPhones;
ErrFatalDisplayIf (recordNum >= DmNumRecords(vars->dbP), "Record outside AddrDB");
ErrFatalDisplayIf (phoneNum >= numPhoneFields, "Phone outside legal range");
tableP = ToolsGetObjectPtr (LookupTable);
// Don't change anything if the same record is selected
if (TblGetSelection(tableP, &row, &column) &&
recordNum == TblGetRowID (tableP, row) &&
phoneNum == TblGetItemInt (tableP, row, 0))
{
return;
}
searchPhones = IsPhoneLookupField(vars->params->field1) ||
IsPhoneLookupField(vars->params->field2);
// See if the record is displayed by one of the rows in the table
// A while is used because if TblFindRowID fails we need to
// call it again to find the row in the reloaded table.
while (true)
{
recordFound = false;
if (TblFindRowID(tableP, recordNum, &row))
{
if (searchPhones)
{
for (; row < TblGetNumberOfRows(tableP); row++)
{
if (TblRowUsable(tableP, row))
{
if (phoneNum == TblGetItemInt(tableP, row, 0) - firstPhoneField)
{
recordFound = true;
break; // match found
}
}
}
}
else
{
recordFound = true;
break; // match found
}
}
// If the record is found in the existing table stop
// and go select it. Otherwise position that table to
// start with the record, reload the table, and look
// for it again.
if (recordFound)
break;
if (vars->hideSecretRecords)
{
// If the record is hidden stop trying to show it.
DmRecordInfo(vars->dbP, recordNum, &attr, NULL, NULL);
if (attr & dmRecAttrSecret)
{
return;
}
}
// Scroll the view down placing the item
// on the top row
vars->topVisibleRecord = recordNum;
vars->topVisibleRecordPhone = phoneNum;
PrvLookupLoadTable(vars);
TblRedrawTable(tableP);
}
// Select the item
TblSelectItem (tableP, row, 0);
vars->currentRecord = recordNum;
vars->currentPhone = phoneNum;
}
/***********************************************************************
*
* FUNCTION: PrvLookupViewLookupString
*
* DESCRIPTION: Adds a character to LookupLookupField, looks up the
* string in the database and selects the item that matches.
*
* PARAMETERS: vars - variables used by the lookup code.
* event - EventPtr containing character to add to LookupLookupField
* or NULL to use the text there
*
* RETURNED: true if the field handled the event
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* Roger 7/9/96 Initial Revision
* meg /2/99 added beepOnFail check before beeping
* vsm 11/07/02 Disabled the complete match check.
***********************************************************************/
Boolean PrvLookupViewLookupString (LookupVariablesPtr vars, EventType * event)
{
FormPtr frm;
UInt16 fldIndex;
FieldPtr fldP;
Char * fldTextP;
TablePtr tableP;
UInt16 foundRecord;
Int16 foundRecordPhone;
Boolean completeMatch;
Boolean uniqueMatch;
#if 0
Int16 length;
#endif
frm = FrmGetActiveForm();
fldIndex = FrmGetObjectIndex(frm, LookupLookupField);
FrmSetFocus(frm, fldIndex);
fldP = FrmGetObjectPtr (frm, fldIndex);
if (event == NULL ||
FldHandleEvent (fldP, event))
{
fldTextP = FldGetTextPtr(fldP);
tableP = FrmGetObjectPtr (frm, FrmGetObjectIndex(frm, LookupTable));
foundRecordPhone = 0;
if (!AddrDBLookupLookupString(vars->dbP, fldTextP, vars->sortByCompany,
vars->params->field1, vars->params->field2, &foundRecord, &foundRecordPhone,
vars->lookupFieldMap, &completeMatch, &uniqueMatch)) //foundRecordPhone
{
// If the user deleted the lookup text remove the
// highlight.
TblUnhighlightSelection(tableP);
}
else
{
PrvLookupViewSelectRecord(vars, foundRecord, foundRecordPhone);
}
#if 0
// This will only work if we have input that doesn't come from the FEP.
if (!completeMatch)
{
// Delete the last character added.
length = FldGetTextLength(fldP);
FldDelete(fldP, length - 1, length);
if (vars->beepOnFail)
{
SndPlaySystemSound (sndError);
//ok, we beeped, if there are more chars in the field, we don;t want to beep again
vars->beepOnFail = false;
}
}
#endif
return true;
}
// Event not handled
return false;
}
/***********************************************************************
*
* FUNCTION: PrvLookupClearLookupString
*
* DESCRIPTION: Clears the LookupLookupField. Does not unhighlight the item.
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* Roger 7/9/96 Initial Revision
*
***********************************************************************/
void PrvLookupClearLookupString ()
{
FormPtr frm;
UInt16 fldIndex;
FieldPtr fldP;
Int16 length;
frm = FrmGetActiveForm();
// FrmSetFocus(frm, noFocus);
fldIndex = FrmGetObjectIndex(frm, LookupLookupField);
fldP = FrmGetObjectPtr (frm, fldIndex);
length = FldGetTextLength(fldP);
if (length > 0)
FldDelete(fldP, 0, length);
}
/***********************************************************************
*
* FUNCTION: PrvLookupViewUseSelection
*
* DESCRIPTION: Use the record currently selected.
*
* PARAMETERS: vars - variables used by the lookup code.
*
* RETURNED: true if a record was selected and false if not.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* Roger 11/11/96 Initial Revision
*
***********************************************************************/
Boolean PrvLookupViewUseSelection (LookupVariablesPtr vars)
{
TablePtr table;
Int16 row;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -