📄 addredit.c
字号:
if (record.fields[fieldNum] == NULL)
newSize = 1;
else
newSize = StrLen(record.fields[fieldNum]) + 1;
// Have the field stop using the chunk to unlock it. Otherwise the resize can't
// move the chunk if more space is needed and no adjacent free space exists.
FldSetTextHandle (fld, 0);
if (!MemHandleResize(textH, newSize))
{
textP = MemHandleLock(textH);
if (newSize > 1)
StrCopy(textP, record.fields[fieldNum]);
else
textP[0] = '\0';
MemPtrUnlock(textP);
}
else
{
ErrNonFatalDisplay("Resize failed.");
}
// Update the text field to use whatever text we have.
FldSetTextHandle (fld, textH);
MemHandleUnlock(recordH);
FrmAlert(DeviceFullAlert);
// The field may no longer be the same height. This row and those
// below may need to be recalced. Mark this row and those
// below it not usable and reload the table.
numOfRows = TblGetNumberOfRows(table);
while (row < numOfRows)
{
TblSetRowUsable(table, row, false);
row++;
}
#ifdef ADDR_FOCUS_FIX
PrvEditLoadTable(FrmGetActiveForm(), true);
#else /* not ifdef ADDR_FOCUS_FIX */
PrvEditLoadTable(FrmGetActiveForm());
#endif /* not ifdef ADDR_FOCUS_FIX */
redraw = true; // redraw the table showing change lost
}
}
// Free the memory used for the field's text because the table suppresses it.
FldFreeMemory (fld);
return redraw;
}
/***********************************************************************
*
* FUNCTION: PrvEditSaveRecord
*
* DESCRIPTION: Checks the record and saves it if it's OK
*
* PARAMETERS: event - a pointer to an EventType structure
*
* RETURNED: The view that should be switched to.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* rsf 9/20/95 Initial Revision
*
***********************************************************************/
UInt16 PrvEditSaveRecord ()
{
MemHandle currentRecordH;
AddrDBRecordType currentRecord;
FormPtr frmP;
TablePtr tableP;
Boolean hasData;
Err err;
// Make sure the field being edited is saved
frmP = FrmGetFormPtr (EditView);
tableP = ToolsGetFrmObjectPtr(frmP, EditTable);
TblReleaseFocus(tableP);
// If this record is needed then leave. This is a good time because
// the data is saved and this is before the record could be deleted.
if (RecordNeededAfterEditView)
{
ListViewSelectThisRecord = noRecord;
return ListView;
}
// The record may have already been delete by the Delete menu command
// or the details dialog. If there isn't a CurrentRecord assume the
// record has been deleted.
if (CurrentRecord == noRecord)
{
ListViewSelectThisRecord = noRecord;
return ListView;
}
// If there is no data then then delete the record.
// If there is data but no name data then demand some.
err = AddrDBGetRecord(AddrDB, CurrentRecord, ¤tRecord, ¤tRecordH);
if (err)
{
ListViewSelectThisRecord = noRecord;
return ListView;
}
hasData = AddrDBRecordContainsData(¤tRecord);
// Unlock before the DeleteRecord. We can only rely on
// NULL pointers from here on out.
MemHandleUnlock(currentRecordH);
// If none are the fields contained anything then
// delete the field.
if (!hasData)
{
ToolsDeleteRecord(false); // uniq ID wasted? Yes. We don't care.
return ListView;
}
// The record's category may have been changed. The CurrentCategory
// isn't supposed to change in this case. Make sure the CurrentRecord
// is still visible in this category or pick another one near it.
if (!ToolsSeekRecord(&CurrentRecord, 0, dmSeekBackward))
if (!ToolsSeekRecord(&CurrentRecord, 0, dmSeekForward))
CurrentRecord = noRecord;
ListViewSelectThisRecord = CurrentRecord;
return ListView;
}
/***********************************************************************
*
* FUNCTION: PrvEditSelectCategory
*
* DESCRIPTION: This routine handles selection, creation and deletion of
* categories from the "Edit View".
*
* PARAMETERS: nothing
*
* RETURNED: The index of the new category.
*
* The following global variables are modified:
* CurrentCategory
* ShowAllCategories
* CategoryName
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 06/05/95 Initial Revision
* gap 08/13/99 Update to use new constant categoryDefaultEditCategoryString.
*
***********************************************************************/
void PrvEditSelectCategory (void)
{
UInt16 attr;
FormType* frmP;
UInt16 category;
Boolean categoryEdited;
// Process the category popup list.
DmRecordInfo (AddrDB, CurrentRecord, &attr, NULL, NULL);
category = attr & dmRecAttrCategoryMask;
frmP = FrmGetActiveForm();
categoryEdited = CategorySelect (AddrDB, frmP, EditCategoryTrigger,
EditCategoryList, false, &category, CategoryName, 1, categoryDefaultEditCategoryString);
if (categoryEdited || (category != (attr & dmRecAttrCategoryMask)))
{
// Change the category of the record.
DmRecordInfo (AddrDB, CurrentRecord, &attr, NULL, NULL);
attr &= ~dmRecAttrCategoryMask;
attr |= category | dmRecAttrDirty;
DmSetRecordInfo (AddrDB, CurrentRecord, &attr, NULL);
ToolsChangeCategory (category);
}
}
/***********************************************************************
*
* FUNCTION: PrvEditUpdateScrollers
*
* DESCRIPTION: This routine draws or erases the edit view scroll arrow
* buttons.
*
* PARAMETERS: frmP - pointer to the address edit form
* bottomField - field index of the last visible row
* lastItemClipped - true if the last visible row is clip at
* the bottom
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 6/26/95 Initial Revision
*
***********************************************************************/
void PrvEditUpdateScrollers (FormPtr frmP, UInt16 bottomFieldIndex,
Boolean lastItemClipped)
{
UInt16 upIndex;
UInt16 downIndex;
Boolean scrollableUp;
Boolean scrollableDown;
// If the first field displayed is not the fist field in the record,
// enable the up scroller.
scrollableUp = TopVisibleFieldIndex > 0;
// If the last field displayed is not the last field in the record,
// enable the down scroller.
scrollableDown = (lastItemClipped || (bottomFieldIndex < editLastFieldIndex));
// Update the scroll button.
upIndex = FrmGetObjectIndex (frmP, EditUpButton);
downIndex = FrmGetObjectIndex (frmP, EditDownButton);
FrmUpdateScrollers (frmP, upIndex, downIndex, scrollableUp, scrollableDown);
}
/***********************************************************************
*
* FUNCTION: PrvEditGetFieldHeight
*
* DESCRIPTION: This routine initialize a row in the to do list.
*
* PARAMETERS: table - pointer to the table of to do items
* fieldIndex - the index of the field displayed in the row
* columnWidth - height of the row in pixels
*
* RETURNED: height of the field in pixels
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 6/26/95 Initial Revision
* art 9/11/97 Add font support.
*
***********************************************************************/
UInt16 PrvEditGetFieldHeight (TablePtr table, UInt16 fieldIndex, Int16 columnWidth, Int16 maxHeight, AddrDBRecordPtr record, FontID * fontIdP)
{
Int16 row;
Int16 column;
UInt16 index;
Int16 height;
UInt16 lineHeight;
FontID currFont;
Char * str;
FieldPtr fld;
if (TblEditing (table))
{
TblGetSelection (table, &row, &column);
if (fieldIndex == TblGetRowID (table, row))
{
fld = TblGetCurrentField (table);
str = FldGetTextPtr (fld);
}
else
{
index = FieldMap[fieldIndex];
str = record->fields[index];
}
}
else
{
index = FieldMap[fieldIndex];
str = record->fields[index];
}
// If the field has text empty, or the field is the current field, or
// the font used to display blank lines is the same as the font used
// to display text then used the view's current font setting.
if ( (str && *str) ||
(CurrentFieldIndex == fieldIndex) ||
(AddrEditFont == addrEditBlankFont))
{
*fontIdP = AddrEditFont;
currFont = FntSetFont (*fontIdP);
}
// If the height of the font used to display blank lines is the same
// height as the font used to display text then used the view's
// current font setting.
else
{
currFont = FntSetFont (addrEditBlankFont);
lineHeight = FntLineHeight ();
FntSetFont (AddrEditFont);
if (lineHeight == FntLineHeight ())
*fontIdP = AddrEditFont;
else
{
*fontIdP = addrEditBlankFont;
FntSetFont (addrEditBlankFont);
}
}
height = FldCalcFieldHeight (str, columnWidth);
lineHeight = FntLineHeight ();
height = min (height, (maxHeight / lineHeight));
height *= lineHeight;
FntSetFont (currFont);
return (height);
}
/***********************************************************************
*
* FUNCTION: PrvEditDrawBusinessCardIndicator
*
* DESCRIPTION: Draw the business card indicator if the current record is
* the business card.
*
* PARAMETERS: formP - the form containing the business card indicator
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 12/3/97 Initial Revision
*
***********************************************************************/
void PrvEditDrawBusinessCardIndicator (FormPtr formP)
{
UInt32 uniqueID;
DmRecordInfo (AddrDB, CurrentRecord, NULL, &uniqueID, NULL);
if (BusinessCardRecordID == uniqueID)
FrmShowObject(formP, FrmGetObjectIndex (formP, EditViewBusinessCardBmp));
else
FrmHideObject(formP, FrmGetObjectIndex (formP, EditViewBusinessCardBmp));
}
/***********************************************************************
*
* FUNCTION: PrvEditResizeDescription
*
* DESCRIPTION: This routine is called when the height of address
* field is changed as a result of user input.
* If the new height of the field is shorter, more items
* may need to be added to the bottom of the list.
*
* PARAMETERS: event - a pointer to an EventType structure
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* art 6/26/95 Initial Revision
*
***********************************************************************/
void PrvEditResizeDescription (EventType * event)
{
#ifdef ADDR_FOCUS_FIX
Boolean insPtState;
FieldType* fld;
TablePtr table;
RectangleType newBounds;
FormType* frmP;
frmP = FrmGetActiveForm();
// Have the table object resize the field and move the items below
// the field up or down.
table = ToolsGetFrmObjectPtr(frmP, EditTable);
// Add items to the table to fill in the space made available by the
// shorting the field.
PrvEditLoadTable (frmP, true);
TblRedrawTable (table);
#if 0 // vivek : 09/21/2001
if (table->attr.editable)
{
FldHandleEvent (TblGetCurrentField (table), event);
}
#else
// vivek : 09/21/2001
// For the ARM port we can't directly access table->attr.editable.
// But there is no need to access table->attr.editable anyway; this
// attribute is set statically (in the resource).
// I am not even sure why we are calling FldHandleEvent here, but I'll
// let it be in there...
// I am also checking if TblGetCurrentField (table) returned NULL even though
// this function is called when a fldHeightChanged event occurs, so there must
// be a current field....I just didn't want to make any change other than what
// was needed for the port.
fld = TblGetCurrentField (table);
if (fld)
FldHandleEvent (fld, event);
#endif
// Get the current height of the field;
fld = event->data.fldHeightChanged.pField;
FldGetBounds (fld, &newBounds);
newBounds.extent.y = event->data.fldHeightChanged.newHeight;
insPtState = InsPtEnabled ();
InsPtEnable (false);
// Change the size of the field.
FldSetBounds (fld, &newBounds);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -