📄 addredit.c
字号:
// The user selected the label of a field. So, set the table to edit the field to
// the right of the label. Also, mark the row invalid and say that we want to redraw
// it so all the colors and such come out right.
TblReleaseFocus(tableP);
TblUnhighlightSelection(tableP);
TblMarkRowInvalid (tableP, row);
redraw = true;
}
// Make sure the the heights the the field we are exiting and the
// that we are entering are correct. They may be incorrect if the
// font used to display blank line is a different height then the
// font used to display field text.
fieldIndex = TblGetRowID (tableP, row);
if (fieldIndex != CurrentFieldIndex || TblGetCurrentField(tableP) == NULL)
{
AddrDBGetRecord (AddrDB, CurrentRecord, ¤tRecord, ¤tRecordH);
currFont = FntGetFont ();
// Is there a current field and is it empty?
if (CurrentFieldIndex != noFieldIndex &&
!currentRecord.fields[FieldMap[CurrentFieldIndex]])
{
if (TblFindRowID (tableP, CurrentFieldIndex, &currRow))
{
// Is the height of the field correct?
FntSetFont (addrEditBlankFont);
if (FntLineHeight () != TblGetRowHeight (tableP, currRow))
{
TblMarkRowInvalid (tableP, currRow);
redraw = true;
}
}
}
CurrentFieldIndex = fieldIndex;
// Is the newly selected field empty?
fieldNum = FieldMap[fieldIndex];
if (!currentRecord.fields[fieldNum])
{
// Is the height of the field correct?
FntSetFont (AddrEditFont);
if (FntLineHeight () != TblGetRowHeight (tableP, row))
{
TblMarkRowInvalid (tableP, row);
redraw = true;
}
}
// Do before the table focus is released and the record is saved.
MemHandleUnlock (currentRecordH);
if (redraw)
{
fldP = TblGetCurrentField(tableP);
if ( fldP != NULL )
{
FldGetSelection(fldP, &startPosition, &stopPosition); // Save the selection of the field
TblGetSelection(tableP, &currRow, &currCol); // Get the current row so that later we can
// check and ensure that the selection is being
// set for the same row.
}
TblReleaseFocus (tableP);
#ifdef ADDR_FOCUS_FIX
PrvEditLoadTable (frmP, true);
#else /* not ADDR_FOCUS_FIX */
PrvEditLoadTable(frmP);
#endif /* not ADDR_FOCUS_FIX */
TblFindRowID (tableP, fieldIndex, &row);
TblRedrawTable (tableP);
}
FntSetFont (currFont);
}
// Set the focus on the field if necessary
if ( TblGetCurrentField(tableP) == NULL )
{
FieldPtr fldTempP;
FrmSetFocus(frmP, FrmGetObjectIndex(frmP, EditTable));
TblGrabFocus (tableP, row, editDataColumn);
fldTempP = TblGetCurrentField(tableP);
FldGrabFocus(fldTempP);
FldMakeFullyVisible (fldTempP);
}
// Restore the selection of the field or restore the insertion point
if ( redraw && (fldP != NULL) )
{
TblGetSelection(tableP, &row, &currCol);
if ( startPosition != stopPosition && (currRow == row ))
FldSetSelection(fldP, startPosition, stopPosition);
else
FldSetInsPtPosition(fldP, EditFieldPosition);
}
return false;
}
/***********************************************************************
*
* FUNCTION: PrvEditRestoreEditState
*
* DESCRIPTION: This routine restores the edit state of the Edit
*
* PARAMETERS: nothing
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 9/12/97 Initial Revision
*
***********************************************************************/
void PrvEditRestoreEditState( FormType* frmP )
{
Int16 row;
TablePtr table;
FieldPtr fld;
if (CurrentFieldIndex == noFieldIndex) return;
// Find the row that the current field is in.
table = ToolsGetFrmObjectPtr(frmP, EditTable);
if ( ! TblFindRowID (table, CurrentFieldIndex, &row) )
return;
FrmSetFocus(frmP, FrmGetObjectIndex(frmP, EditTable));
TblGrabFocus (table, row, editDataColumn);
// Restore the insertion point position.
fld = TblGetCurrentField (table);
FldSetInsPtPosition (fld, EditFieldPosition);
FldGrabFocus (fld);
}
/***********************************************************************
*
* FUNCTION: PrvEditSetGraffitiMode
*
* DESCRIPTION: Set the graffiti mode based on the field being edited.
*
* PARAMETERS: currentField - the field being edited.
*
* RETURNED: the graffiti mode is set
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 9/20/95 Initial Revision
*
***********************************************************************/
void PrvEditSetGraffitiMode (FieldPtr fld, UInt16 currentField)
{
MemHandle currentRecordH;
Boolean autoShift;
FieldAttrType attr;
AddrDBRecordType currentRecord;
AddrDBGetRecord(AddrDB, CurrentRecord, ¤tRecord, ¤tRecordH);
if (! isPhoneField(currentField))
{
// Set the field to support auto-shift.
autoShift = true;
}
else
{
GrfSetState(false, true, false);
autoShift = false;
}
if (fld)
{
FldGetAttributes (fld, &attr);
attr.autoShift = autoShift;
FldSetAttributes (fld, &attr);
}
MemHandleUnlock(currentRecordH);
}
/***********************************************************************
*
* FUNCTION: PrvEditGetRecordField
*
* DESCRIPTION: This routine returns a pointer to a field of the
* address record. This routine is called by the table
* object as a callback routine when it wants to display or
* edit a field.
*
* PARAMETERS: table - pointer to the memo list table (TablePtr)
* row - row of the table to draw
* column - column of the table to draw
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 6/6/95 Initial Revision
*
***********************************************************************/
Err PrvEditGetRecordField (void * table, Int16 row, Int16 UNUSED_PARAM(column), Boolean editing, MemHandle * textH, Int16 * textOffset, Int16 * textAllocSize, FieldPtr fld)
{
UInt16 fieldNum;
UInt16 fieldIndex;
Char * recordP;
Char * fieldP;
MemHandle recordH, fieldH;
UInt16 fieldSize;
AddrDBRecordType record;
// Get the field number that corresponds to the table item.
// The field number is stored as the row id.
//
fieldIndex = TblGetRowID (table, row);
fieldNum = FieldMap[fieldIndex];
AddrDBGetRecord (AddrDB, CurrentRecord, &record, &recordH);
if (editing)
{
PrvEditSetGraffitiMode(fld, fieldNum);
if (record.fields[fieldNum])
{
fieldSize = StrLen(record.fields[fieldNum]) + 1;
fieldH = MemHandleNew(fieldSize); // Handle freeing done into PrvEditSaveRecordField() by calling FldFreeMemory() function
fieldP = MemHandleLock(fieldH);
MemMove(fieldP, record.fields[fieldNum], fieldSize);
*textAllocSize = fieldSize;
MemHandleUnlock(fieldH);
}
else
{
fieldH = 0;
*textAllocSize = 0;
}
MemHandleUnlock (recordH);
*textOffset = 0; // only one string
*textH = fieldH;
return (0);
}
else
{
// Calculate the offset from the start of the record.
recordP = MemHandleLock (recordH); // record now locked twice
if (record.fields[fieldNum])
{
*textOffset = record.fields[fieldNum] - recordP;
*textAllocSize = StrLen (record.fields[fieldNum]) + 1; // one for null terminator
}
else
{
do
{
fieldNum++;
} while (fieldNum < addressFieldsCount &&
record.fields[fieldNum] == NULL);
if (fieldNum < addressFieldsCount)
*textOffset = record.fields[fieldNum] - recordP;
else
// Place the new field at the end of the text.
*textOffset = MemHandleSize(recordH);
*textAllocSize = 0; // one for null terminator
}
MemHandleUnlock (recordH); // unlock the second lock
}
MemHandleUnlock (recordH); // unlock the AddrGetRecord lock
*textH = recordH;
return (0);
}
/***********************************************************************
*
* FUNCTION: PrvEditSaveRecordField
*
* DESCRIPTION: This routine saves a field of an address to the
* database. This routine is called by the table
* object, as a callback routine, when it wants to save
* an item.
*
* PARAMETERS: table - pointer to the memo list table (TablePtr)
* row - row of the table to draw
* column - column of the table to draw
*
* RETURNED: true if the table needs to be redrawn
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 2/21/95 Initial Revision
*
***********************************************************************/
Boolean PrvEditSaveRecordField (void * table, Int16 row, Int16 UNUSED_PARAM(column))
{
UInt16 fieldNum;
UInt16 fieldIndex;
FieldPtr fld;
AddrDBRecordType record;
MemHandle recordH;
MemHandle textH;
Char * textP;
AddrDBRecordFlags bit;
UInt16 i;
Err err;
Boolean redraw = false;
UInt16 numOfRows;
Int16 newSize;
fld = TblGetCurrentField (table);
textH = FldGetTextHandle(fld);
// Get the field number that corresponds to the table item to save.
fieldIndex = TblGetRowID (table, row);
fieldNum = FieldMap[fieldIndex];
// Save the field last edited.
EditRowIDWhichHadFocus = fieldIndex;
// Save the cursor position of the field last edited.
// Check if the top of the text is scroll off the top of the
// field, if it is then redraw the field.
if (FldGetScrollPosition (fld))
{
FldSetScrollPosition (fld, 0);
EditFieldPosition = 0;
}
else
EditFieldPosition = FldGetInsPtPosition (fld);
// Make sure there any selection is removed since we will free
// the text memory before the callee can remove the selection.
FldSetSelection (fld, 0, 0);
if (FldDirty (fld))
{
// Since the field is dirty, mark the record as dirty
ToolsDirtyRecord (CurrentRecord);
// Get a pointer to the text of the field.
if (textH == 0)
textP = NULL;
else
{
textP = MemHandleLock(textH);
if (textP[0] == '\0')
textP = NULL;
}
// If we have text, and saving an auto-fill field, save the data to the proper database
if (textP) {
UInt32 dbType = 0;
if (UseAutoFill != kDontUseAutoFill)
{
// Select the proper database for the field we are editing,
// or skip if not an autofill enabled field
switch (fieldNum) {
case title: dbType = titleDBType; break;
case company: dbType = companyDBType; break;
case city: dbType = cityDBType; break;
case state: dbType = stateDBType; break;
case country: dbType = countryDBType; break;
default: dbType = 0;
}
}
if (dbType) AutoFillLookupSave(dbType, sysFileCAddress, textP);
}
AddrDBGetRecord (AddrDB, CurrentRecord, &record, &recordH);
record.fields[fieldNum] = textP;
// If we have changed a phone field and if the show if
// list view phone is blank set it to the first non blank phone
// This rule should allow:
// 1. Showing a blank field is possible
// 2. Deleting the shown field switches to another
// 3. Adding a field when there isn't one shows it.
if (isPhoneField(fieldNum) &&
record.fields[firstPhoneField + record.options.phones.displayPhoneForList] == NULL)
{
for (i = firstPhoneField; i <= lastPhoneField; i++)
{
if (record.fields[i] != NULL)
{
record.options.phones.displayPhoneForList = i - firstPhoneField;
break;
}
}
}
bit.allBits = (UInt32)1 << fieldNum;
err = AddrDBChangeRecord(AddrDB, &CurrentRecord, &record, bit);
// The new field has been copied into the new record. Unlock it.
if (textP)
MemPtrUnlock(textP);
// The change was not made (probably storage out of memory)
if (err)
{
// Because the storage is full the text in the text field differs
// from the text in the record. PrvEditGetFieldHeight uses
// the text in the field (because it's being edited).
// Make the text in the field the same as the text in the record.
// Resizing should always be possible.
MemHandleUnlock(recordH); // Get original text
AddrDBGetRecord (AddrDB, CurrentRecord, &record, &recordH);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -