📄 address.c
字号:
{
EvtGetEvent (&event, (TickAppButtonPushed == 0) ? evtWaitForever : 2);
if (! SysHandleEvent (&event))
if (! PrvAppHandleKeyDown (&event))
if (! MenuHandleEvent (0, &event, &error))
if (! PrvAppHandleEvent (&event))
FrmDispatchEvent (&event);
#if EMULATION_LEVEL != EMULATION_NONE
// MemHeapCheck(0); // Check the dynamic heap after every event
// MemHeapCheck(1); // Check the first heap after every event
#endif
}
while (event.eType != appStopEvent);
}
/***********************************************************************
*
* FUNCTION: PrvAppHandleKeyDown
*
* DESCRIPTION: Handle the key being down.
*
* PARAMETERS: event - a pointer to an EventType structure
*
* RETURNED: true if the event was handled and should not be passed on
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 10/22/97 Initial Revision
*
***********************************************************************/
Boolean PrvAppHandleKeyDown (EventType * event)
{
// Check if a button being held down is released
if (TickAppButtonPushed != 0)
{
// This is the case when the button is let up
if ((KeyCurrentState() & (keyBitHard1 | keyBitHard2 | keyBitHard3 | keyBitHard4)) == 0)
{
if (BusinessCardSentForThisButtonPress)
{
BusinessCardSentForThisButtonPress = false;
TickAppButtonPushed = 0;
// Allow the masked off key to now send keyDownEvents.
KeySetMask(keyBitsAll);
}
else if (event->eType == nilEvent)
{
// Send the keyDownEvent to the app. It was stripped out
// before but now it can be sent over the nullEvent. It
// may be nullChr from when the app was launched. In that case
// we don't need to send the app's key because the work expected,
// which was switching to this app, has already been done.
if (AppButtonPushed != nullChr)
{
event->eType = keyDownEvent;
event->data.keyDown.chr = AppButtonPushed;
event->data.keyDown.modifiers = AppButtonPushedModifiers;
}
TickAppButtonPushed = 0;
// Allow the masked off key to now send keyDownEvents.
KeySetMask(keyBitsAll);
}
}
// This is the case when the button is depresed long enough to send the business card
else if (TickAppButtonPushed + AppButtonPushTimeout <= TimGetTicks() &&
!BusinessCardSentForThisButtonPress)
{
BusinessCardSentForThisButtonPress = true;
ToolsAddrBeamBusinessCard(AddrDB);
}
}
else if (event->eType == keyDownEvent)
{
if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr) &&
!(event->data.keyDown.modifiers & autoRepeatKeyMask))
{
// Remember which hard key is mapped to the Address Book
// because it may need to be sent later.
AppButtonPushed = event->data.keyDown.chr;
AppButtonPushedModifiers = event->data.keyDown.modifiers;
TickAppButtonPushed = TimGetTicks();
// Mask off the key to avoid repeat keys causing clicking sounds
KeySetMask(~KeyCurrentState());
// Don't process the key
return true;
}
}
return false;
}
/***********************************************************************
*
* FUNCTION: PrvAppHandleEvent
*
* DESCRIPTION: This routine loads form resources and set the event
* handler for the form loaded.
*
* 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 9/11/95 Initial Revision
* jmp 9/17/99 Use NewNoteView instead of NoteView.
* aro 06/22/00 Add AddrListDialog
*
***********************************************************************/
Boolean PrvAppHandleEvent (EventType * event)
{
UInt16 formId;
FormPtr frm;
if (event->eType == frmLoadEvent)
{
// Load the form resource.
formId = event->data.frmLoad.formID;
frm = FrmInitForm (formId);
FrmSetActiveForm (frm);
// Set the event handler for the form. The handler of the currently
// active form is called by FrmHandleEvent each time is receives an
// event.
switch (formId)
{
case ListView:
FrmSetEventHandler(frm, ListHandleEvent);
break;
case RecordView:
FrmSetEventHandler(frm, ViewHandleEvent);
break;
case EditView:
FrmSetEventHandler(frm, EditHandleEvent);
break;
case NewNoteView:
FrmSetEventHandler(frm, NoteViewHandleEvent);
break;
case DetailsDialog:
FrmSetEventHandler(frm, DetailsHandleEvent);
break;
case CustomEditDialog:
FrmSetEventHandler(frm, CustomEditHandleEvent);
break;
case PreferencesDialog:
FrmSetEventHandler(frm, PrefsHandleEvent);
break;
case DialListDialog:
FrmSetEventHandler(frm, DialListHandleEvent);
break;
default:
ErrNonFatalDisplay("Invalid Form Load Event");
break;
}
return (true);
}
return (false);
}
/***********************************************************************
*
* FUNCTION: PrvAppSearch
*
* DESCRIPTION: This routine searches the the address database for records
* contains the string passed.
*
* PARAMETERS: findParams
*
* RETURNED: nothing
*
* HISTORY:
* 06/05/95 art Created by Art Lamb.
* 10/21/99 jmp Changed params to findParams to match other routines
* like this one.
* 11/30/00 kwk Use TxtFindString to avoid trap dispatch from FindStrInStr.
* Save returned match length as appCustom in FindSaveMatch.
*
***********************************************************************/
void PrvAppSearch(FindParamsPtr findParams)
{
AddrAppInfoPtr appInfoPtr;
AddrDBRecordType record;
Boolean done;
Boolean match;
WChar appSearchPhoneLabelLetters[numPhoneLabels];
Char * header;
Char * unnamedRecordStringPtr = NULL;
MemHandle unnamedRecordStringH = NULL;
DmOpenRef dbP;
DmSearchStateType PrvAppSearchState;
Err err;
MemHandle headerStringH;
LocalID dbID;
RectangleType r;
UInt16 cardNo=0;
UInt16 recordNum;
MemHandle recordH;
UInt16 i;
UInt32 matchPos;
UInt16 matchLen;
// Find the application's data file.
err = DmGetNextDatabaseByTypeCreator (true, &PrvAppSearchState, addrDBType,
sysFileCAddress, true, &cardNo, &dbID);
if (err)
{
findParams->more = false;
return;
}
// Open the address database.
dbP = DmOpenDatabase(cardNo, dbID, findParams->dbAccesMode);
if (!dbP)
{
findParams->more = false;
return;
}
// Display the heading line.
headerStringH = DmGetResource(strRsc, FindAddrHeaderStr);
header = MemHandleLock(headerStringH);
done = FindDrawHeader (findParams, header);
MemHandleUnlock(headerStringH);
DmReleaseResource(headerStringH);
if (done)
goto Exit;
// PrvAppSearch the description and note fields for the "find" string.
recordNum = findParams->recordNum;
while (true)
{
// Because applications can take a long time to finish a find when
// the result may be on the screen or for other reasons, users like
// to be able to stop the find. Stop the find if an event is pending.
// This stops if the user does something with the device. Because
// this call slows down the PrvAppSearch we perform it every so many
// records instead of every record. The response time should still
// be Int16 without introducing much extra work to the PrvAppSearch.
// Note that in the implementation below, if the next 16th record is
// secret the check doesn't happen. Generally this shouldn't be a
// problem since if most of the records are secret then the PrvAppSearch
// won't take long anyways!
if ((recordNum & 0x000f) == 0 && // every 16th record
EvtSysEventAvail(true))
{
// Stop the PrvAppSearch process.
findParams->more = true;
break;
}
recordH = DmQueryNextInCategory (dbP, &recordNum, dmAllCategories);
// Have we run out of records?
if (! recordH)
{
findParams->more = false;
break;
}
// PrvAppSearch all the fields of the address record.
AddrDBGetRecord (dbP, recordNum, &record, &recordH);
match = false;
for (i = 0; i < addrNumFields; i++)
{
if (record.fields[i])
{
match = TxtFindString(record.fields[i], findParams->strToFind, &matchPos, &matchLen);
if (match)
{
break;
}
}
}
if (match)
{
// Add the match to the find paramter block, if there is no room to
// display the match the following function will return true.
done = FindSaveMatch (findParams, recordNum, matchPos, i, matchLen, cardNo, dbID);
if (done)
{
MemHandleUnlock(recordH);
break;
}
// Get the bounds of the region where we will draw the results.
FindGetLineBounds (findParams, &r);
appInfoPtr = (AddrAppInfoPtr) AddrDBAppInfoGetPtr(dbP);
ToolsInitPhoneLabelLetters(appInfoPtr, appSearchPhoneLabelLetters);
// Display the title of the description.
FntSetFont (stdFont);
ToolsDrawRecordNameAndPhoneNumber (&record, &r, appSearchPhoneLabelLetters, appInfoPtr->misc.sortByCompany, &unnamedRecordStringPtr, &unnamedRecordStringH);
MemPtrUnlock(appInfoPtr);
findParams->lineNumber++;
}
MemHandleUnlock(recordH);
recordNum++;
}
if ( unnamedRecordStringPtr != 0 )
MemPtrUnlock(unnamedRecordStringPtr);
if ( unnamedRecordStringH != 0 )
DmReleaseResource(unnamedRecordStringH);
Exit:
DmCloseDatabase (dbP);
}
/***********************************************************************
*
* FUNCTION: PrvAppGoToItem
*
* DESCRIPTION: This routine is a entry point of this application.
* It is generally call as the result of hiting of
* "Go to" button in the text PrvAppSearch dialog.
*
* PARAMETERS: recordNum -
*
* RETURNED: nothing
*
* HISTORY:
* 07/12/95 rsf Created by Roger Flores.
* 09/17/99 jmp Use NewNoteView instead of NoteView.
* 11/30/00 kwk Set frmGoto.matchLen to be matchCustom, since we
* pass the match length returned by TxtFindString to
* FindSaveMatch in the appCustom parameter.
*
***********************************************************************/
void PrvAppGoToItem (GoToParamsPtr goToParams, Boolean launchingApp)
{
UInt16 formID;
UInt16 recordNum;
UInt16 attr;
UInt32 uniqueID;
EventType event;
recordNum = goToParams->recordNum;
if (!DmQueryRecord(AddrDB, recordNum))
{
// Record isn't accessible. This can happen when receiving a beam while in the
// Address New form. This prevents a fatal alert, but doesn't fix the off-by-one
// error. (See DOLATER in sysAppLaunchCmdExgReceiveData case.)
if (!ToolsSeekRecord(&recordNum, 0, dmSeekBackward))
if (!ToolsSeekRecord(&recordNum, 0, dmSeekForward))
{
FrmAlert(secGotoInvalidRecordAlert);
FrmGotoForm(ListView);
return;
}
}
DmRecordInfo (AddrDB, recordNum, &attr, &uniqueID, NULL);
// Change the current category if necessary.
if (CurrentCategory != dmAllCategories)
{
CurrentCategory = attr & dmRecAttrCategoryMask;
}
// If the application is already running, close all the open forms. If
// the current record is blank, then it will be deleted, so we'll
// the record's unique id to find the record index again, after all
// the forms are closed.
if (! launchingApp)
{
FrmCloseAllForms ();
DmFindRecordByID (AddrDB, uniqueID, &recordNum);
}
// Set global variables that keep track of the currently record.
CurrentRecord = recordNum;
// Set PriorAddressFormID so the Note View returns to the List View
PriorAddressFormID = ListView;
if (goToParams->matchFieldNum == note)
formID = NewNoteView;
else
formID = RecordView;
MemSet (&event, sizeof(EventType), 0);
// Send an event to load the form we want to goto.
event.eType = frmLoadEvent;
event.data.frmLoad.formID = formID;
EvtAddEventToQueue (&event);
// Send an event to goto a form and select the matching text.
event.eType = frmGotoEvent;
event.data.frmGoto.formID = formID;
event.data.frmGoto.recordNum = recordNum;
event.data.frmGoto.matchPos = goToParams->matchPos;
event.data.frmGoto.matchLen = goToParams->matchCustom;
event.data.frmGoto.matchFieldNum = goToParams->matchFieldNum;
EvtAddEventToQueue (&event);
}
/***********************************************************************
*
* FUNCTION: PrvAppHandleSync
*
* DESCRIPTION: MemHandle details after the database has been synchronized.
* This app resorts the database.
*
* PARAMETERS: findParams
*
* RETURNED: nothing
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 8/31/95 Initial Revision
* vmk 10/17/95 Changed to open db read/write
* jmp 10/01/99 Changed call to DmOpenDatabaseByTypeCreator() to
* AddrGetDatabase().
*
***********************************************************************/
void PrvAppHandleSync(void)
{
DmOpenRef dbP;
AddrAppInfoPtr appInfoPtr;
Err err;
// Find the application's data file.
err = AddrDBGetDatabase (&dbP, dmModeReadWrite);
if (err)
return;
appInfoPtr = (AddrAppInfoPtr) AddrDBAppInfoGetPtr(dbP);
AddrDBChangeSortOrder(dbP, appInfoPtr->misc.sortByCompany);
MemPtrUnlock(appInfoPtr);
DmCloseDatabase (dbP);
}
/***********************************************************************
*
* FUNCTION: PrvAppLaunchCmdDatabaseInit
*
* DESCRIPTION: Initialize an empty database.
*
* PARAMETERS: dbP - pointer to database opened for read & write
*
* RETURNED: true if successful
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 10/19/95 Initial Revision
*
***********************************************************************/
Boolean PrvAppLaunchCmdDatabaseInit(DmOpenRef dbP)
{
Err err;
if (!dbP)
return false;
// Set the backup bit. This is to aid syncs with non Palm software.
ToolsSetDBAttrBits(dbP, dmHdrAttrBackup);
// Initialize the database's app info block
err = AddrDBAppInfoInit (dbP);
if (err)
return false;
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -