📄 addrlist.c
字号:
/******************************************************************************
*
* Copyright (c) 1995-2003 PalmSource, Inc. All rights reserved.
*
* File: AddrList.c
*
* Release: Palm OS 5 SDK (68K) R3.
*
* Description:
* This is the Address Book application's list form module.
*
*****************************************************************************/
#include "AddrList.h"
#include "AddrView.h"
#include "AddrEdit.h"
#include "AddrDialList.h"
#include "Address.h"
#include "AddrTools.h"
#include "AddrNote.h"
#include "AddrDefines.h"
#include "AddressRsc.h"
#include "AddressTransfer.h"
#include <TextMgr.h>
#include <ErrorMgr.h>
#include <SoundMgr.h>
#include <TimeMgr.h>
#include <AboutBox.h>
#include <Category.h>
#include <Menu.h>
#include <UIResources.h>
/***********************************************************************
*
* Defines
*
***********************************************************************/
// Address list table columns
#define nameAndNumColumn 0
#define noteColumn 1
// Scroll rate values
#define scrollDelay 2
#define scrollAcceleration 2
#define scrollSpeedLimit 5
/***********************************************************************
*
* Global variables
*
***********************************************************************/
// These are used for accelerated scrolling
static UInt16 LastSeconds = 0;
static UInt16 ScrollUnits = 0;
/***********************************************************************
*
* Internal Functions
*
***********************************************************************/
static void PrvListInit( FormType* frmP );
static void PrvListSelectRecord( FormType* frmP, UInt16 recordNum, Boolean forceSelection );
static void PrvListScroll( WinDirectionType direction, UInt16 units, Boolean byLine );
static void PrvListResetScrollRate(void);
static void PrvListAdjustScrollRate(void);
static Boolean PrvListLookupString (EventType * event);
static void PrvListDrawRecord (void * table, Int16 row, Int16 column, RectanglePtr bounds);
static void PrvListClearLookupString ();
static void PrvListUpdateDisplay( UInt16 updateCode );
static UInt16 PrvListNumberOfRows (TablePtr table);
static void PrvListUpdateScrollButtons( FormType* frmP );
static void PrvListLoadTable( FormType* frmP );
static UInt16 PrvListSelectCategory (void);
static void PrvListNextCategory (void);
static Boolean PrvListDeleteRecord (void);
static Boolean PrvListDoCommand (UInt16 command);
static Boolean PrvListHandleRecordSelection( EventType* event );
static void PrvListReplaceTwoColors (const RectangleType *rP, UInt16 cornerDiam, UIColorTableEntries oldForeground, UIColorTableEntries oldBackground, UIColorTableEntries newForeground, UIColorTableEntries newBackground);
/***********************************************************************
*
* FUNCTION: ListHandleEvent
*
* DESCRIPTION: This routine is the event handler for the "List 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
* frigino 8/15/97 Added scroll rate acceleration using
* PrvListResetScrollRate() and PrvListAdjustScrollRate()
* jmp 9/17/99 Use NewNoteView instead of NoteView.
* peter 4/25/00 Add support for un-masking just the selected record.
* peter 5/08/00 Add support for tapping on phone numbers to dial.
* aro 6/22/00 Add check for dialing abilities
* aro 9/25/00 use cmdTextH rather than cmdText to avoir unreleased resource
*
***********************************************************************/
Boolean ListHandleEvent (EventType* event)
{
FormType* frmP;
Boolean handled = false;
TablePtr table;
Int16 row;
Int16 column;
MemHandle cmdTextH;
UInt32 numLibs;
switch (event->eType)
{
case frmOpenEvent:
frmP = FrmGetActiveForm ();
PrvListInit (frmP);
// Make sure the record to be selected is one of the table's rows or
// else it reloads the table with the record at the top. Nothing is
// drawn by this because the table isn't visible.
if (ListViewSelectThisRecord != noRecord)
PrvListSelectRecord(frmP, ListViewSelectThisRecord, false);
FrmDrawForm (frmP);
// Select the record. This finds which row to select it and does it.
if (ListViewSelectThisRecord != noRecord)
{
PrvListSelectRecord(frmP, ListViewSelectThisRecord, true);
ListViewSelectThisRecord = noRecord;
}
// Set the focus in the lookup field so that the user can easily
// bring up the keyboard.
FrmSetFocus(frmP, FrmGetObjectIndex(frmP, ListLookupField));
PriorAddressFormID = FrmGetFormId (frmP);
// Check the dialing abilities
// Only the first call is long and further called are fast
// So it's better to do it the first time the form is drawn
if (!ToolsIsDialerPresent())
EnableTapDialing = false;
handled = true;
break;
case frmCloseEvent:
if (UnnamedRecordStringPtr)
{
MemPtrUnlock(UnnamedRecordStringPtr);
UnnamedRecordStringPtr = NULL;
}
if (UnnamedRecordStringH)
{
DmReleaseResource(UnnamedRecordStringH);
UnnamedRecordStringH = NULL;
}
break;
case tblEnterEvent:
handled = PrvListHandleRecordSelection (event);
break;
case tblSelectEvent:
if (TblRowMasked(event->data.tblSelect.pTable,
event->data.tblSelect.row))
{
if (SecVerifyPW (showPrivateRecords) == true)
{
// We only want to unmask this one record, so restore the preference.
PrefSetPreference (prefShowPrivateRecords, maskPrivateRecords);
event->data.tblSelect.column = nameAndNumColumn; //force non-note view
}
else
break;
}
// An item in the list of names and phone numbers was selected, go to
// the record view.
CurrentRecord = TblGetRowID (event->data.tblSelect.pTable,
event->data.tblSelect.row);
// 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;
EditRowIDWhichHadFocus = editFirstFieldIndex;
EditFieldPosition = 0;
if (event->data.tblSelect.column == nameAndNumColumn)
FrmGotoForm (RecordView);
else
if (NoteViewCreate())
FrmGotoForm (NewNoteView);
handled = true;
break;
case ctlEnterEvent:
switch (event->data.ctlEnter.controlID)
{
case ListUpButton:
case ListDownButton:
// Reset scroll rate
PrvListResetScrollRate();
// Clear lookup string
PrvListClearLookupString ();
// leave unhandled so the buttons can repeat
break;
}
break;
case ctlSelectEvent:
switch (event->data.ctlSelect.controlID)
{
case ListCategoryTrigger:
PrvListSelectCategory ();
handled = true;
break;
case ListNewButton:
EditNewRecord();
handled = true;
break;
}
break;
case ctlRepeatEvent:
// Adjust the scroll rate if necessary
PrvListAdjustScrollRate();
switch (event->data.ctlRepeat.controlID)
{
case ListUpButton:
PrvListScroll (winUp, ScrollUnits, false);
// leave unhandled so the buttons can repeat
break;
case ListDownButton:
PrvListScroll (winDown, ScrollUnits, false);
// leave unhandled so the buttons can repeat
break;
default:
break;
}
break;
case keyDownEvent:
// Address Book key pressed for the first time?
if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr))
{
if (! (event->data.keyDown.modifiers & poweredOnKeyMask))
{
PrvListClearLookupString ();
PrvListNextCategory ();
handled = true;
}
}
else if (EvtKeydownIsVirtual(event))
{
switch (event->data.keyDown.chr)
{
case vchrPageUp:
// Reset scroll rate if not auto repeating
if ((event->data.keyDown.modifiers & autoRepeatKeyMask) == 0)
{
PrvListResetScrollRate();
}
// Adjust the scroll rate if necessary
PrvListAdjustScrollRate();
PrvListScroll (winUp, ScrollUnits, false);
PrvListClearLookupString ();
handled = true;
break;
case vchrPageDown:
// Reset scroll rate if not auto repeating
if ((event->data.keyDown.modifiers & autoRepeatKeyMask) == 0)
{
PrvListResetScrollRate();
}
// Adjust the scroll rate if necessary
PrvListAdjustScrollRate();
PrvListScroll (winDown, ScrollUnits, false);
PrvListClearLookupString ();
handled = true;
break;
case vchrSendData:
if (CurrentRecord != noRecord)
{
MenuEraseStatus (0);
TransferSendRecord(AddrDB, CurrentRecord, exgBeamPrefix, NoDataToBeamAlert);
}
else
SndPlaySystemSound (sndError);
handled = true;
break;
}
}
else if (event->data.keyDown.chr == linefeedChr)
{
frmP = FrmGetActiveForm ();
table = FrmGetObjectPtr (frmP, FrmGetObjectIndex (frmP, ListTable));
if (TblGetSelection (table, &row, &column))
{
// 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;
FrmGotoForm (RecordView);
}
handled = true;
}
else
handled = PrvListLookupString(event);
break;
case fldChangedEvent:
PrvListLookupString(event);
handled = true;
break;
case menuEvent:
return PrvListDoCommand (event->data.menu.itemID);
case menuCmdBarOpenEvent:
if (CurrentRecord != noRecord)
{
// because this isn't a real menu command, get the text for the button from a resource
cmdTextH = DmGetResource (strRsc, DeleteRecordStr);
MenuCmdBarAddButton(menuCmdBarOnLeft, BarDeleteBitmap, menuCmdBarResultMenuItem, ListRecordDeleteRecordCmd, MemHandleLock(cmdTextH));
MemHandleUnlock(cmdTextH);
DmReleaseResource(cmdTextH);
}
MenuCmdBarAddButton(menuCmdBarOnLeft, BarSecureBitmap, menuCmdBarResultMenuItem, ListOptionsSecurityCmd, 0);
if (CurrentRecord != noRecord)
{
// because this isn't a real menu command, get the text for the button from a resource
cmdTextH = DmGetResource (strRsc, BeamRecordStr);
MenuCmdBarAddButton(menuCmdBarOnLeft, BarBeamBitmap, menuCmdBarResultMenuItem, ListRecordBeamRecordCmd, MemHandleLock(cmdTextH));
MemHandleUnlock(cmdTextH);
DmReleaseResource(cmdTextH);
}
// tell the field package to not add cut/copy/paste buttons automatically; we
// don't want it for the lookup field since it'd cause confusion.
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(ListRecordDialCmd);
if (ExgGetRegisteredApplications(NULL, &numLibs, NULL, NULL, exgRegSchemeID, exgSendScheme) || !numLibs)
MenuHideItem(ListRecordSendCategoryCmd);
else
MenuShowItem(ListRecordSendCategoryCmd);
// don't set handled = true
break;
case frmUpdateEvent:
PrvListUpdateDisplay (event->data.frmUpdate.updateCode);
handled = true;
break;
default:
break;
}
return (handled);
}
#pragma mark -
/***********************************************************************
*
* FUNCTION: PrvListInit
*
* DESCRIPTION: This routine initializes the "List View" 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
* ---- ---- -----------
* art 6/5/95 Initial Revision
*
***********************************************************************/
void PrvListInit( FormType* frmP )
{
UInt16 row;
UInt16 rowsInTable;
TableType* tblP;
ControlPtr ctl;
if (ShowAllCategories)
CurrentCategory = dmAllCategories;
// Initialize the address list table.
tblP = ToolsGetFrmObjectPtr(frmP, ListTable);
rowsInTable = TblGetNumberOfRows(tblP);
for (row = 0; row < rowsInTable; row++)
{
TblSetItemStyle(tblP, row, nameAndNumColumn, customTableItem);
TblSetItemStyle(tblP, row, noteColumn, customTableItem);
TblSetRowUsable(tblP, row, false);
}
TblSetColumnUsable(tblP, nameAndNumColumn, true);
TblSetColumnUsable(tblP, noteColumn, true);
TblSetColumnMasked(tblP, nameAndNumColumn, true);
TblSetColumnMasked(tblP, noteColumn, true);
// Set the callback routine that will draw the records.
TblSetCustomDrawProcedure (tblP, nameAndNumColumn, PrvListDrawRecord);
TblSetCustomDrawProcedure (tblP, noteColumn, PrvListDrawRecord);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -