📄 addredit.c
字号:
else
handled = PrvEditAutoFill(event);
break;
case frmUpdateEvent:
PrvEditUpdateDisplay(event->data.frmUpdate.updateCode);
handled = true;
break;
case frmSaveEvent:
// Save the field being edited. Do not delete the record if it's
// empty because a frmSaveEvent can be sent without the form being
// closed. A canceled find does this.
frmP = FrmGetFormPtr (EditView);
tableP = ToolsGetFrmObjectPtr(frmP, EditTable);
TblReleaseFocus(tableP);
break;
default:
break;
}
return (handled);
}
/***********************************************************************
*
* FUNCTION: EditNewRecord
*
* DESCRIPTION: Makes a new record with some setup
*
* PARAMETERS: event - a pointer to an EventType structure
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 6/13/95 Initial Revision
*
***********************************************************************/
void EditNewRecord ()
{
AddrDBRecordType newRecord;
AddressFields i;
UInt16 attr;
Err err;
// Set up the new record
newRecord.options.phones.displayPhoneForList = 0;
newRecord.options.phones.phone1 = workLabel;
newRecord.options.phones.phone2 = homeLabel;
newRecord.options.phones.phone3 = faxLabel;
newRecord.options.phones.phone4 = otherLabel;
newRecord.options.phones.phone5 = emailLabel;
for (i = firstAddressField; i < addressFieldsCount; i++)
{
newRecord.fields[i] = NULL;
}
err = AddrDBNewRecord(AddrDB, &newRecord, &CurrentRecord);
if (err)
{
FrmAlert(DeviceFullAlert);
return;
}
// Set it's category to the category being viewed.
// If the category is All then set the category to unfiled.
DmRecordInfo (AddrDB, CurrentRecord, &attr, NULL, NULL);
attr &= ~dmRecAttrCategoryMask;
attr |= ((CurrentCategory == dmAllCategories) ? dmUnfiledCategory :
CurrentCategory) | dmRecAttrDirty;
DmSetRecordInfo (AddrDB, CurrentRecord, &attr, NULL);
// Set the global variable that determines which field is the top visible
// field in the edit view. Also done when New is pressed.
TopVisibleFieldIndex = 0;
CurrentFieldIndex = editFirstFieldIndex;
EditRowIDWhichHadFocus = editFirstFieldIndex;
EditFieldPosition = 0;
FrmGotoForm (EditView);
}
#pragma mark -
#ifdef ADDR_FOCUS_FIX
/***********************************************************************
*
* FUNCTION: PrvEditTblGetFirstUsableRow
*
* DESCRIPTION: This routine returns the first row in a table that
* in usable (displayable)
*
* PARAMETERS: table - pointer to a table object
*
* RETURNED: row - row index (zero based) or -1 if there are no
* usable rows.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* konno 09/28/98 Initial Revision (Copied from TblGetLastUsableRow)
*
***********************************************************************/
static UInt16
PrvEditTblGetFirstUsableRow (const TablePtr table)
{
Int16 row;
Int16 numRows = TblGetNumberOfRows (table);
for (row = 0; row < numRows; row += 1)
{
if (TblRowUsable(table, row))
{
return (row);
}
}
return ((UInt16) -1);
}
#else /* not ADDR_FOCUS_FIX */
#endif /* not ADDR_FOCUS_FIX */
/***********************************************************************
*
* FUNCTION: PrvEditInit
*
* DESCRIPTION: This routine initializes the "Edit View" of the
* Address application.
*
* PARAMETERS: frmP Pointer to the Edit form structure
* leaveDataLocked T=>keep app info, form map data locked.
*
* RETURNED: nothing
*
* HISTORY:
* 06/05/99 art Created by Art Lamb.
* 07/29/99 kwk Set up locked FieldMap pointer.
* 09/21/00 aro GetObjectPtr => GetFrmObjectPtr
*
***********************************************************************/
void PrvEditInit( FormPtr frmP, Boolean leaveDataLocked )
{
UInt16 attr;
UInt16 row;
UInt16 rowsInTable;
UInt16 category;
UInt16 dataColumnWidth;
TablePtr table;
AddrAppInfoPtr appInfoPtr;
ListPtr popupPhoneList;
FontID currFont;
RectangleType bounds;
MemHandle autoFillH;
#ifdef ADDR_FOCUS_FIX
Boolean doFocusFix = !leaveDataLocked;
#endif
currFont = FntSetFont (stdFont);
appInfoPtr = (AddrAppInfoPtr) AddrDBAppInfoGetPtr(AddrDB);
FieldMapH = DmGetResource(fieldMapRscType, FieldMapID);
FieldMap = (const AddressFields*)MemHandleLock(FieldMapH);
CurrentTableRow = editInvalidRow;
// Set the choices to the phone list
EditPhoneListChoices[0] = appInfoPtr->fieldLabels[firstPhoneField];
EditPhoneListChoices[1] = appInfoPtr->fieldLabels[firstPhoneField + 1];
EditPhoneListChoices[2] = appInfoPtr->fieldLabels[firstPhoneField + 2];
EditPhoneListChoices[3] = appInfoPtr->fieldLabels[firstPhoneField + 3];
EditPhoneListChoices[4] = appInfoPtr->fieldLabels[firstPhoneField + 4];
EditPhoneListChoices[5] = appInfoPtr->fieldLabels[addressFieldsCount];
EditPhoneListChoices[6] = appInfoPtr->fieldLabels[addressFieldsCount + 1];
EditPhoneListChoices[7] = appInfoPtr->fieldLabels[addressFieldsCount + 2];
popupPhoneList = ToolsGetFrmObjectPtr(frmP, EditPhoneList);
LstSetListChoices(popupPhoneList, EditPhoneListChoices, numPhoneLabels);
LstSetHeight (popupPhoneList, numPhoneLabels);
// Determine whether we can use auto-fill.
autoFillH = DmGetResource(constantRscType, kAutoFillConstantID);
ErrNonFatalDisplayIf(!autoFillH, "You are missing the auto-fill tint resource");
if (autoFillH)
{
UseAutoFill = *(UInt32 *)MemHandleLock(autoFillH);
ErrNonFatalDisplayIf((UseAutoFill != 0) && (UseAutoFill != 1), "Autofill value can be only 0 or 1");
MemHandleUnlock(autoFillH);
DmReleaseResource(autoFillH);
}
// Initialize the address list table.
table = ToolsGetFrmObjectPtr(frmP, EditTable);
rowsInTable = TblGetNumberOfRows (table);
for (row = 0; row < rowsInTable; row++)
{
// This sets the data column
TblSetItemStyle (table, row, editDataColumn, textTableItem);
TblSetRowUsable (table, row, false);
}
TblSetColumnUsable (table, editLabelColumn, true);
TblSetColumnUsable (table, editDataColumn, true);
TblSetColumnSpacing (table, editLabelColumn, spaceBeforeDesc);
// Set the callback routines that will load and save the
// description field.
TblSetLoadDataProcedure (table, editDataColumn, PrvEditGetRecordField);
TblSetSaveDataProcedure (table, editDataColumn, PrvEditSaveRecordField);
// Set the column widths so that the label column contents fit exactly.
// Those labels change as the country changes.
if (EditLabelColumnWidth == 0)
EditLabelColumnWidth = ToolsGetLabelColumnWidth (appInfoPtr, stdFont);
// Compute the width of the data column, account for the table column gutter.
TblGetBounds (table, &bounds);
dataColumnWidth = bounds.extent.x - spaceBeforeDesc - EditLabelColumnWidth;
TblSetColumnWidth(table, editLabelColumn, EditLabelColumnWidth);
TblSetColumnWidth(table, editDataColumn, dataColumnWidth);
#ifdef ADDR_FOCUS_FIX
PrvEditLoadTable (frmP, doFocusFix);
#else /* not ifdef ADDR_FOCUS_FIX */
PrvEditLoadTable(frmP);
#endif /* not ifdef ADDR_FOCUS_FIX */
// Set the label of the category trigger.
if (CurrentCategory == dmAllCategories)
{
DmRecordInfo (AddrDB, CurrentRecord, &attr, NULL, NULL);
category = attr & dmRecAttrCategoryMask;
}
else
category = CurrentCategory;
CategoryGetName (AddrDB, category, CategoryName);
CategorySetTriggerLabel(ToolsGetFrmObjectPtr(frmP, EditCategoryTrigger), CategoryName);
FntSetFont (currFont);
// if the caller is using us to reset the form, then we don't want
// to repeatedly lock down the app info block.
if (!leaveDataLocked)
{
MemPtrUnlock(appInfoPtr);
MemHandleUnlock(FieldMapH);
DmReleaseResource(FieldMapH);
}
// In general, the record isn't needed after this form is closed.
// It is if the user is going to the Note View. In that case
// we must keep the record.
RecordNeededAfterEditView = false;
}
/***********************************************************************
*
* FUNCTION: PrvEditInitTableRow
*
* DESCRIPTION: This routine initialize a row in the edit view.
*
* PARAMETERS: table - pointer to the table of to do items
* row - row number (first row is zero)
* fieldIndex - the index of the field displayed in the row
* rowHeight - height of the row in pixels
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 6/26/95 Initial Revision
*
***********************************************************************/
void PrvEditInitTableRow( FormType* frmP, TablePtr table, UInt16 row, UInt16 fieldIndex, Int16 rowHeight, FontID fontID, AddrDBRecordPtr record, AddrAppInfoPtr appInfoPtr )
{
// Make the row usable.
TblSetRowUsable (table, row, true);
// Set the height of the row to the height of the desc
TblSetRowHeight (table, row, rowHeight);
// Store the record number as the row id.
TblSetRowID (table, row, fieldIndex);
// Mark the row invalid so that it will draw when we call the
// draw routine.
TblMarkRowInvalid (table, row);
// Set the text font.
TblSetItemFont (table, row, editDataColumn, fontID);
// The label is either a text label or a popup menu (of phones)
if (! isPhoneField(FieldMap[fieldIndex]))
{
TblSetItemStyle (table, row, editLabelColumn, labelTableItem);
TblSetItemPtr (table, row, editLabelColumn,
appInfoPtr->fieldLabels[FieldMap[fieldIndex]]);
}
else
{
// The label is a popup list
TblSetItemStyle (table, row, editLabelColumn, popupTriggerTableItem);
TblSetItemInt (table, row, editLabelColumn, GetPhoneLabel(record, FieldMap[fieldIndex]));
TblSetItemPtr (table, row, editLabelColumn, ToolsGetFrmObjectPtr(frmP, EditPhoneList));
}
}
/***********************************************************************
*
* FUNCTION: PrvEditHandleSelectField
*
* DESCRIPTION: Handle the user tapping an edit view field label.
* Either the a phone label is changed or the user wants to edit
* a field by tapping on it's label.
*
* PARAMETERS: row - row of the item to select (zero based)
* column - column of the item to select (zero based)
*
* RETURNED: true if the event was handled and nothing else should
* be done
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 11/27/95 Cut from EditViewHandleEvent
* art 09/02/97 Add multi-font support
* roger 11/04/97 Changed parameters to support another routine
* jmp 04/18/00 Fixed bug #23237: When changing an editLabelColumn,
* mark the row invalid so that we redraw everything.
* If we don't do this, the edit indicator's colors
* don't come out correctly.
* fpa 10/23/00 Fixed bug #42762 - Can't select text when cursor
* is in a blank field
* gap 10/25/00 fix above did not take into account that there are
* occasions where fldP is NULL.
* fpa 11/06/00 Fixed bug #23088 - Cannot insert a cursor between 2
* characters. Undid gap above modification because it
* was reopening bug #42762
*
***********************************************************************/
Boolean PrvEditHandleSelectField (Int16 row, Int16 column)
{
Err err;
Int16 currRow, currCol;
UInt16 fieldNum;
UInt16 fieldIndex;
MemHandle currentRecordH;
UInt16 i;
UInt16 currentField;
FontID currFont;
Boolean redraw = false;
FormType* frmP;
TablePtr tableP;
FieldPtr fldP;
AddrDBRecordType currentRecord;
AddrDBRecordFlags changedFields;
UInt16 startPosition;
UInt16 stopPosition;
frmP = FrmGetActiveForm();
tableP = ToolsGetFrmObjectPtr(frmP, EditTable);
fldP = NULL;
TraceOutput(TL(appErrorClass, "PrvEditHandleSelectField"));
// If a phone label was changed then modify the record
currentField = FieldMap[TblGetRowID(tableP, row)];
if (column == editLabelColumn)
{
if (isPhoneField(currentField))
{
i = TblGetItemInt(tableP, row, editLabelColumn);
AddrDBGetRecord(AddrDB, CurrentRecord, ¤tRecord, ¤tRecordH);
switch (currentField)
{
case firstPhoneField:
currentRecord.options.phones.phone1 = i;
break;
case firstPhoneField + 1:
currentRecord.options.phones.phone2 = i;
break;
case firstPhoneField + 2:
currentRecord.options.phones.phone3 = i;
break;
case firstPhoneField + 3:
currentRecord.options.phones.phone4 = i;
break;
case firstPhoneField + 4:
currentRecord.options.phones.phone5 = i;
break;
}
changedFields.allBits = 0;
err = AddrDBChangeRecord(AddrDB, &CurrentRecord, ¤tRecord,
changedFields);
if ( err != errNone )
{
MemHandleUnlock(currentRecordH);
FrmAlert(DeviceFullAlert);
// Redraw the table without the change. The phone label
// is unchanged in the record but the screen and the table row
// are changed. Reinit the table to fix it. Mark the row
// invalid and redraw it.
PrvEditInit(frmP, false);
TblMarkRowInvalid(tableP, row);
TblRedrawTable(tableP);
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -