📄 addrview.c
字号:
/******************************************************************************
*
* Copyright (c) 1995-2003 PalmSource, Inc. All rights reserved.
*
* File: AddrView.c
*
* Release: Palm OS 5 SDK (68K) R3.
*
* Description:
* This is the Address Book application's view form module.
*
*****************************************************************************/
#include "AddrView.h"
#include "AddrDialList.h"
#include "AddrEdit.h"
#include "AddrDetails.h"
#include "AddrNote.h"
#include "Address.h"
#include "AddrTools.h"
#include "AddressRsc.h"
#include "AddrDefines.h"
#include "AddressTransfer.h"
#include <TextMgr.h>
#include <ErrorMgr.h>
#include <SoundMgr.h>
#include <StringMgr.h>
#include <AboutBox.h>
#include <Category.h>
#include <Menu.h>
#include <UIResources.h>
#include <TraceMgr.h>
// number of record view lines to store
#define recordViewLinesMax 55
#define recordViewBlankLine 0xffff // Half height if the next line.x == 0
// Resource type used to specify order of fields in Edit view.
#define fieldMapRscType 'fmap'
#define USE_TEMPLATES 1
#define enableTemplatesConstRscID 1700
/***********************************************************************
*
* Internal Structures
*
***********************************************************************/
// Info on how to draw the record view
typedef struct
{
UInt16 fieldNum;
UInt16 length;
UInt16 offset;
UInt16 x;
UInt16 prefixStrID;
UInt16 suffixStrID;
UInt16 blockID;
} RecordViewLineType;
/***********************************************************************
*
* Global variables
*
***********************************************************************/
static AddrDBRecordType recordViewRecord;
static MemHandle recordViewRecordH = 0;
static RecordViewLineType *RecordViewLines = NULL;
static UInt16 RecordViewLastLine; // Line after last one containing data
static UInt16 TopRecordViewLine;
static UInt16 RecordViewFirstPlainLine;
static UInt16 RecordViewLayoutRowNum; // Counter for the rows in all the layouts being drawn.
// This is used to switch the font after the first row.
/***********************************************************************
*
* Internal Functions
*
***********************************************************************/
static void PrvViewOpen(void);
static void PrvViewClose(void);
static void PrvViewInit( FormType* frm );
static void PrvViewNewLine (UInt16 *width);
static void PrvViewAddSpaceForText (const Char * const string, UInt16 *width);
static void PrvViewPositionTextAt (UInt16 *width, const UInt16 position);
static void PrvViewAddField (const UInt16 fieldNum, UInt16 *width, const UInt16 maxWidth, const UInt16 indentation,
const UInt16 prefixStrID, const UInt16 suffixStrID, const UInt16 blockID);
static void PrvViewErase( FormType* frmP );
static UInt16 PrvViewCalcNextLine(UInt16 i, UInt16 oneLine);
static void PrvViewDrawSelectedText (UInt16 currentField, UInt16 selectPos, UInt16 selectLen, UInt16 textY);
static void PrvViewDraw ( FormType* frmP, UInt16 selectFieldNum, UInt16 selectPos, UInt16 selectLen, Boolean drawOnlySelectField );
static void PrvViewDrawBusinessCardIndicator (FormPtr formP);
static void PrvViewUpdate( FormType* frmP );
static UInt16 PrvViewScrollOnePage (Int16 newTopRecordViewLine, WinDirectionType direction);
static void PrvViewScroll (WinDirectionType direction);
static void PrvViewMakeVisible (UInt16 selectFieldNum, UInt16 selectPos, UInt16 selectLen);
static Boolean PrvViewPhoneNumberAt (Int16 x, Int16 y, UInt16 *fieldNumP, UInt16 *offsetP, UInt16 *lengthP);
static Boolean PrvViewHandleTapOnPhoneNumber (UInt16 fieldNum, UInt16 offset, UInt16 length);
static Boolean PrvViewHandlePen (EventType * event);
static Boolean PrvViewDoCommand (UInt16 command);
static Boolean PrvViewInitUsingTemplate(AddrAppInfoPtr appInfoPtr, UInt16 maxWidth);
static void PrvGetBlockLayout(AddrDBRecordType* viewRecP, UInt16 resID, ViewRowIndexLayoutType *outRowIndexLayoutP);
static Boolean PrvGetAlternateLayoutID(AddrDBRecordType* viewRecP, UInt16 resId, UInt16 *outID);
static void PrvAddSpaceForBlockLayout(AddrDBRecordType* viewRecP, AddrAppInfoPtr appInfoPtr, UInt16 blockID, UInt16 maxWidth);
static Boolean PrvViewDrawUsingTemplate ( FormType* frmP, UInt16 selectFieldNum, UInt16 selectPos, UInt16 selectLen, Boolean drawOnlySelectField );
/***********************************************************************
*
* FUNCTION: ViewHandleEvent
*
* DESCRIPTION: This routine is the event handler for the "Address View"
* of the Address Book 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
* ---- ---- -----------
* art 6/5/95 Initial Revision
* jmp 10/01/99 Fix frmUpdateEvent so that it redraws the form
* and updated the RecordView now that we can get
* into a situation where the bits might not necessarily
* be restored except through and update event itself.
* FPa 11/28/00 kFrmCustomUpdateEvent handling
*
***********************************************************************/
Boolean ViewHandleEvent(EventType * event)
{
UInt32 numLibs;
Boolean handled = false;
FormType* frmP;
switch (event->eType)
{
case frmOpenEvent:
PrvViewOpen();
handled = true;
break;
case frmCloseEvent:
PrvViewClose();
break;
case ctlSelectEvent:
switch (event->data.ctlSelect.controlID)
{
case RecordDoneButton:
// When we return to the ListView highlight this record.
ListViewSelectThisRecord = CurrentRecord;
FrmGotoForm (ListView);
handled = true;
break;
case RecordEditButton:
FrmGotoForm (EditView);
handled = true;
break;
case RecordNewButton:
EditNewRecord();
handled = true;
break;
default:
break;
}
break;
case penDownEvent:
handled = PrvViewHandlePen(event);
break;
case ctlRepeatEvent:
switch (event->data.ctlRepeat.controlID)
{
case RecordUpButton:
PrvViewScroll(winUp);
// leave unhandled so the buttons can repeat
break;
case RecordDownButton:
PrvViewScroll(winDown);
// leave unhandled so the buttons can repeat
break;
default:
break;
}
break;
case keyDownEvent:
if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr))
{
FrmGotoForm (ListView);
handled = true;
}
else if (EvtKeydownIsVirtual(event))
{
switch (event->data.keyDown.chr)
{
case vchrPageUp:
PrvViewScroll (winUp);
handled = true;
break;
case vchrPageDown:
PrvViewScroll (winDown);
handled = true;
break;
case vchrSendData:
TransferSendRecord(AddrDB, CurrentRecord, exgBeamPrefix, NoDataToBeamAlert);
handled = true;
break;
default:
break;
}
}
break;
case menuEvent:
return PrvViewDoCommand (event->data.menu.itemID);
case menuCmdBarOpenEvent:
MenuCmdBarAddButton(menuCmdBarOnLeft, BarDeleteBitmap, menuCmdBarResultMenuItem, RecordRecordDeleteRecordCmd, 0);
MenuCmdBarAddButton(menuCmdBarOnLeft, BarBeamBitmap, menuCmdBarResultMenuItem, RecordRecordBeamRecordCmd, 0);
// tell the field package to not add cut/copy/paste buttons automatically
event->data.menuCmdBarOpen.preventFieldButtons = true;
// don't set handled to true; this event must fall through to the system.
break;
case menuOpenEvent:
if(!ToolsIsDialerPresent())
MenuHideItem(RecordRecordDialCmd);
if (ExgGetRegisteredApplications(NULL, &numLibs, NULL, NULL, exgRegSchemeID, exgSendScheme) || !numLibs)
MenuHideItem(RecordRecordSendRecordCmd);
else
MenuShowItem(RecordRecordSendRecordCmd);
// don't set handled = true
break;
case frmUpdateEvent:
// Do not use ActiveForm here since the update event is broadcasted to all open forms
TraceOutput(TL(appErrorClass, "ViewHandleEvent() - frmUpdateEvent"));
frmP = FrmGetFormPtr(RecordView);
FrmDrawForm(frmP);
PrvViewUpdate(frmP);
handled = true;
break;
case kFrmCustomUpdateEvent:
// Event sent by Custom view because when custom fields are renamed, it can be necessary to recalculate view screen display: if the width of the custom field is enlarged (and if its content can only be displayed using 2 lines), its content can be displayed on the next line
PrvViewClose();
PrvViewOpen();
handled = true;
break;
case frmGotoEvent:
TraceOutput(TL(appErrorClass, "ViewHandleEvent() - event->data.frmGoto.matchLen = %hu", event->data.frmGoto.matchLen));
frmP = FrmGetActiveForm ();
CurrentRecord = event->data.frmGoto.recordNum;
PrvViewInit(frmP);
PrvViewMakeVisible(event->data.frmGoto.matchFieldNum, event->data.frmGoto.matchPos, event->data.frmGoto.matchLen);
FrmDrawForm(frmP);
PrvViewDraw(frmP, event->data.frmGoto.matchFieldNum, event->data.frmGoto.matchPos, event->data.frmGoto.matchLen, false);
PriorAddressFormID = FrmGetFormId(frmP);
handled = true;
break;
default:
break;
}
return (handled);
}
#pragma mark -
/***********************************************************************
*
* FUNCTION: PrvViewOpen
*
* DESCRIPTION: This routine is called when frmOpenEvent is received
*
* PARAMETERS: None
*
* RETURNED: None
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* FPa 11/28/00 Initial Revision
*
***********************************************************************/
void PrvViewOpen(void)
{
FormType* frmP;
frmP = FrmGetActiveForm ();
PrvViewInit(frmP);
FrmDrawForm(frmP);
PrvViewDraw(frmP, 0, 0, 0, false);
PrvViewDrawBusinessCardIndicator(frmP);
PriorAddressFormID = FrmGetFormId(frmP);
}
/***********************************************************************
*
* FUNCTION: PrvViewClose
*
* DESCRIPTION: This routine is called when frmCloseEvent is received
*
* PARAMETERS: None
*
* RETURNED: None
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* FPa 11/28/00 Initial Revision
* FPa 12/05/00 Added MemHandleUnlock
*
***********************************************************************/
void PrvViewClose(void)
{
MemHandle handle;
if (recordViewRecordH)
{
MemHandleUnlock(recordViewRecordH);
recordViewRecordH = 0;
}
if (RecordViewLines)
{
handle = MemPtrRecoverHandle(RecordViewLines);
MemHandleUnlock(handle);
MemHandleFree(handle);
RecordViewLines = 0;
}
}
/***********************************************************************
*
* FUNCTION: PrvViewInit
*
* DESCRIPTION: This routine initializes the "Record View" of the
* Address application. Most importantly it lays out the
* record and decides how the record is drawn.
*
* PARAMETERS: frm - pointer to the view form.
*
* RETURNED: true if the event was handled and should not be passed
* to a higher level handler.
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 6/21/95 Initial Revision
* aro 09/25/00 Add fieldMapH to release the resource properly
* FPa 11/27/00 Do not add company field if this field is blank
*
***********************************************************************/
void PrvViewInit( FormType* frm )
{
UInt16 attr;
UInt16 index;
UInt16 category;
AddrAppInfoPtr appInfoPtr;
MemHandle RecordViewLinesH;
UInt16 width = 0;
RectangleType r;
UInt16 maxWidth;
FontID curFont;
UInt16 i;
UInt16 fieldIndex;
UInt16 phoneLabelNum;
const AddressFields* fieldMap;
MemHandle fieldMapH;
Int16 cityIndex = -1;
Int16 zipIndex = -1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -