📄 addrcustom.c
字号:
/******************************************************************************
*
* Copyright (c) 1995-2003 PalmSource, Inc. All rights reserved.
*
* File: AddrCustom.c
*
* Release: Palm OS 5 SDK (68K) R3.
*
* Description:
* This is the Address Book "Rename Custom Fields" screen
*
*****************************************************************************/
#include "AddrCustom.h"
#include "AddressDB.h"
#include "AddressRsc.h"
#include "AddrTools.h"
#include "Address.h"
#include <Form.h>
#include <StringMgr.h>
#include <UIResources.h>
/***********************************************************************
*
* Internal Functions
*
***********************************************************************/
static void CustomEditSave (FormPtr frm);
static void CustomEditInit (FormPtr frm);
static UInt16 PrvGetLastRenamableCustomFieldID (void);
/***********************************************************************
*
* FUNCTION: CustomEditSave
*
* DESCRIPTION: Write the renamed field labels
*
* PARAMETERS: frm
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 2/23/95 Initial Revision
*
***********************************************************************/
void CustomEditSave (FormPtr frm)
{
UInt16 index, lastCustomRenameableLabel;
FieldPtr fld;
UInt16 objNumber;
Char *textP;
AddrAppInfoPtr appInfoPtr;
Boolean sendUpdate = false;
// Get the object number of the first field.
objNumber = FrmGetObjectIndex (frm, CustomEditFirstField);
lastCustomRenameableLabel = PrvGetLastRenamableCustomFieldID();
// For each dirty field update the corresponding label.
for (index = firstRenameableLabel; index <= lastCustomRenameableLabel; index++)
{
fld = FrmGetObjectPtr (frm, objNumber++);
if (FldDirty(fld))
{
sendUpdate = true;
textP = FldGetTextPtr(fld);
if (textP)
AddrDBSetFieldLabel(AddrDB, index, textP);
}
}
if (sendUpdate)
{
// Update the column width since a label changed.
appInfoPtr = (AddrAppInfoPtr) AddrDBAppInfoGetPtr(AddrDB);
EditLabelColumnWidth = ToolsGetLabelColumnWidth (appInfoPtr, stdFont);
RecordLabelColumnWidth = ToolsGetLabelColumnWidth (appInfoPtr, AddrRecordFont);
MemPtrUnlock(appInfoPtr);
FrmUpdateForm (0, updateCustomFieldLabelChanged);
}
}
/***********************************************************************
*
* FUNCTION: CustomEditInit
*
* DESCRIPTION: Load field labels for editing.
*
* PARAMETERS: frm
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 2/23/95 Initial Revision
*
***********************************************************************/
void CustomEditInit (FormPtr frm)
{
UInt16 index, lastCustomRenameableLabel;
UInt16 length;
FieldPtr fld;
UInt16 objNumber;
MemHandle textH;
Char *textP;
AddrAppInfoPtr appInfoPtr;
addressLabel *fieldLabels;
lastCustomRenameableLabel = PrvGetLastRenamableCustomFieldID();
// Get the object number of the first field.
objNumber = FrmGetObjectIndex (frm, CustomEditFirstField);
appInfoPtr = (AddrAppInfoPtr) AddrDBAppInfoGetPtr(AddrDB);
fieldLabels = appInfoPtr->fieldLabels;
// For each label, allocate some global heap space and copy the
// the string to the global heap. Then set a field to use the
// copied string for editing. If the field is unused no space is
// allocated. The field will allocate space if text is typed in.
for (index = firstRenameableLabel; index <= lastCustomRenameableLabel; index++)
{
fld = FrmGetObjectPtr (frm, objNumber++);
length = StrLen(fieldLabels[index]);
if (length > 0)
{
length += 1; // include space for a null terminator
textH = MemHandleNew(length);
if (textH)
{
textP = MemHandleLock(textH);
MemMove(textP, fieldLabels[index], length);
FldSetTextHandle (fld, textH);
MemHandleUnlock(textH);
}
}
}
MemPtrUnlock(appInfoPtr);
}
/***********************************************************************
*
* FUNCTION: CustomEditHandleEvent
*
* DESCRIPTION: This routine is the event handler for the "Edit Custom
* Fields" of the Address application.
*
* PARAMETERS: event - a pointer to an EventType structure
*
* RETURNED: true if the event was handled and should not be passed
* to a higher level handler.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 06/23/95 Initial Revision
* FPa 11/28/00 Sends an event when OK button pressed
*
***********************************************************************/
Boolean CustomEditHandleEvent (EventType * event)
{
Boolean handled = false;
FormPtr frm;
if (event->eType == ctlSelectEvent)
{
switch (event->data.ctlSelect.controlID)
{
case CustomEditOkButton:
{
EventType evt;
frm = FrmGetActiveForm();
CustomEditSave(frm);
ToolsLeaveForm();
evt.eType = kFrmCustomUpdateEvent;
EvtAddEventToQueue(&evt); // We send this event because View screen needs to recalculate its display when Custom fields are renamed
handled = true;
break;
}
case CustomEditCancelButton:
ToolsLeaveForm();
handled = true;
break;
default:
break;
}
}
else if (event->eType == frmOpenEvent)
{
frm = FrmGetActiveForm ();
CustomEditInit (frm);
FrmDrawForm (frm);
handled = true;
}
return (handled);
}
/***********************************************************************
*
* FUNCTION: PrvGetLastRenamableCustomFieldID
*
* DESCRIPTION: This routine gets the last renamable custom field id. It
* first looks for a soft constant that specifies the value;
* if the resource doesn't exist it uses the default custom4.
*
* PARAMETERS: none.
*
* RETURNED: The last renamable custom field.
*
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* vsm 2002-10-07 Initial Revision.
*
***********************************************************************/
static UInt16 PrvGetLastRenamableCustomFieldID (void)
{
MemHandle constantHdl;
UInt16 lastCustomRenameableLabel = lastRenameableLabel;
constantHdl = DmGetResource(constantRscType, CustomEditLastRenameLabelConst);
ErrNonFatalDisplayIf(!constantHdl, "You need to define tint 1900 for the lastRenameableLabel.");
if (constantHdl)
{
UInt32 temp;
temp = *(UInt32 *)MemHandleLock(constantHdl);
lastCustomRenameableLabel = temp;
MemHandleUnlock(constantHdl);
ErrNonFatalDisplayIf((lastCustomRenameableLabel > lastRenameableLabel)
|| (lastCustomRenameableLabel < firstRenameableLabel), "Incorrect last custom field value" );
}
return lastCustomRenameableLabel;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -