datebook.c

来自「我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codew」· C语言 代码 · 共 1,772 行 · 第 1/4 页

C
1,772
字号
 *
 * DESCRIPTION: This routine is called as the result of hitting the 
 *              "Go to" button in the text search dialog. 
 *
 * PARAMETERS:	 goToParams   - where to go to.
 *              launchingApp - true if the application is being launched
 *
 * RETURNED:	 nothing
 *
 *	HISTORY:
 *		08/23/95	art	Created by Art Lamb.
 *		08/03/99	kwk	Use custom param to set up match length.
 *		04/12/00	ryw	Fixed MemSet parameter ordering.
 *
 ***********************************************************************/
void GoToItem (GoToParamsPtr goToParams, Boolean launchingApp)
{
	UInt16 formID;
	UInt16 recordNum;
	EventType event;
	UInt32 uniqueID;

	recordNum = goToParams->recordNum;
	
	if (!DmQueryRecord(ApptDB, recordNum))
	{
		// Record isn't accessible. This can happen when receiving a beam with an
		// empty record. This prevents a fatal alert, but doesn't fix the off-by-one
		// error. (See DOLATER in sysAppLaunchCmdExgReceiveData case.)
		if (!SeekCurrentRecord(ApptDB, &recordNum, 0, dmSeekBackward))
			if (!SeekCurrentRecord(ApptDB, &recordNum, 0, dmSeekForward))
			{
				FrmAlert(secGotoInvalidRecordAlert);
				FrmGotoForm(DayView);
				return;
			}
	}

	// If the application is already running, destroy the UI, this may 
	// change the index of record we're going to.
	if (! launchingApp)
		{
		DmRecordInfo (ApptDB, recordNum, NULL, &uniqueID, NULL); 
		FrmCloseAllForms ();
		ClearEditState ();
		DmFindRecordByID (ApptDB, uniqueID, &recordNum);
		}
		
	// Go to day view or note view.
	if (goToParams->matchFieldNum == noteSeacrchFieldNum)
		formID = NewNoteView;
	else
		formID = DayView;

	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:    GoToAlarmItem
 *
 * DESCRIPTION: This routine is called as the result of hitting the 
 *              "Go to" button in the attention manager dialog.
 *
 * PARAMETERS:	 UniqueID   - uniqueID of the item to go to.
 *
 * RETURNED:	 nothing
 *
 *	HISTORY:
 *		09/07/00 gap	Initial reviesion.
 *
 ***********************************************************************/
void GoToAlarmItem (UInt32 uniqueID)
{
	UInt16	attributes;
	UInt16	recordNum;
	Err		err;
	EventType	event;
	UInt16	cardNo;
	LocalID	dbID;
	DmSearchStateType searchInfo;



#if EMULATION_LEVEL != EMULATION_NONE
		FrmCloseAllForms ();
		ClearEditState ();
#endif	

	// remove the item from the attention manager queue
	DmGetNextDatabaseByTypeCreator (true, &searchInfo, sysFileTApplication, sysFileCDatebook, true, &cardNo, &dbID);
	AttnForgetIt(cardNo, dbID, uniqueID);
	
	// verify that the specified uniqueID is still in the Date Book's database
	// one reason this needs to be done is to prevent crashing should the alarm
	// have been on an untitled event with no note attached.  in the process of 
	// executing the goto, the original record may have been deleted as all 
	// untitled events w/o a note are as soon as the item is deselected.
	err = FindRecordByID (ApptDB, uniqueID, &recordNum);
	if (err)
		{
		FrmGotoForm(DayView);
		return;
		}
	
	// Get the attribute information for the record
	DmRecordInfo (ApptDB, recordNum, &attributes, NULL, NULL);


	// if the user does a "go to" from an attention manager dialog while the
	// private items are hidden and the selected item happens to have the 
	// private bit set, the user must submit his password so that the 
	// security level can be changed from hide to show before the goto to the 
	// specified record occurs
	if ( (attributes & dmRecAttrSecret) && (PrivateRecordVisualStatus == hidePrivateRecords) )
		{		
		if (SecVerifyPW(showPrivateRecords))
			{
			DmCloseDatabase (ApptDB);	
			ApptDB = DmOpenDatabaseByTypeCreator(datebookDBType, sysFileCDatebook, (dmModeReadWrite | dmModeShowSecret));
			PrivateRecordVisualStatus = CurrentRecordVisualStatus = showPrivateRecords;
			}
		else
			{
			FrmGotoForm(DayView);
			return;
			}
		}
		
	MemSet (&event, sizeof(EventType), 0);

	// Send an event to load the form we want to goto.
	event.eType = frmLoadEvent;
	event.data.frmLoad.formID = DayView;
	EvtAddEventToQueue (&event);


	// Send an event to goto a form and select the matching text.
	event.eType = frmGotoEvent;
	event.data.frmGoto.formID = DayView;
	event.data.frmGoto.recordNum = recordNum;
	event.data.frmGoto.matchPos = 0;
	event.data.frmGoto.matchLen = 0;
	event.data.frmGoto.matchFieldNum = 0;
	EvtAddEventToQueue (&event);
}


/***********************************************************************
 *
 * FUNCTION:    DrawTime
 *
 * DESCRIPTION: Draws the given time. Used by the custom draw routines
 *					 for the date columns of the agenda and day views.
 *
 * PARAMETERS:  inTime		- the time
 *              inFormat	- time-to-ascii conversion format
 *					 inBoundsP	- drawing area
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			rbb	6/4/99	Initial Revision
 *
 ***********************************************************************/
void DrawTime (
	TimeType							inTime,
	TimeFormatType					inFormat,
	FontID							inFont,
	JustificationType				inJustification,
	RectangleType*					inBoundsP )
{
	FontID							curFont;
	char								timeStr [timeStringLength];
	TimeFormatType					format;
	UInt16							len;
	UInt16							width;
	Int16								x;

	// No-time appointment?
	if (TimeToInt(inTime) == apptNoTime)
		{
		// Show a centered diamond symbol, overriding the font params
		inFont = symbolFont;
		inJustification  = centerAlign;

		timeStr[0] = symbolNoTime;
		timeStr[1] = '\0';
		}
	else
		{
		if (inFormat == tfColonAMPM)
			format = tfColon;
		 else if (inFormat == tfDotAMPM)
		 	format = tfDot;
		 else
			format = inFormat;

		TimeToAscii (inTime.hours, inTime.minutes, format, timeStr);

		}	
	
	// Use the string width and alignment to compute its starting point
	len = StrLen (timeStr);
	width = FntCharsWidth (timeStr, len);
	x = inBoundsP->topLeft.x;
	switch (inJustification)
		{
		case rightAlign:
			x += inBoundsP->extent.x - width;
			break;
		
		case centerAlign:
			x += (inBoundsP->extent.x - width) / 2;
			break;
		}
	
	x = max (inBoundsP->topLeft.x, x);
	
	// Draw the time
	curFont = FntSetFont (inFont);
	WinDrawChars (timeStr, len, x, inBoundsP->topLeft.y);	
	FntSetFont (curFont);
}


/***********************************************************************
 *
 * FUNCTION:    GetObjectPtr
 *
 * DESCRIPTION: This routine returns a pointer to an object in the current
 *              form.
 *
 * PARAMETERS:  formId - id of the form to display
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	2/21/95	Initial Revision
 *
 ***********************************************************************/
void* GetObjectPtr (UInt16 objectID)
{
	FormPtr frm;
	
	frm = FrmGetActiveForm ();
	return (FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, objectID)));

}


/***********************************************************************
 *
 * FUNCTION:    DirtyRecord
 *
 * DESCRIPTION: Mark a record dirty (modified).  Record marked dirty 
 *              will be synchronized.
 *
 * PARAMETERS:  record index
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	4/15/95	Initial Revision
 *
 ***********************************************************************/
void DirtyRecord (DmOpenRef dbP, UInt16 index)
{
	UInt16		attr;
	Err			err;

	err = DmRecordInfo (dbP, index, &attr, NULL, NULL);
	ErrFatalDisplayIf (err, "Invalid index");
	
	attr |= dmRecAttrDirty;
	DmSetRecordInfo (dbP, index, &attr, NULL);
}


/***********************************************************************
 *
 * FUNCTION:    ClearEditState
 *
 * DESCRIPTION: This routine take the application out of edit mode.
 *              The edit state of the current record is remember until
 *              this routine is called.  
 *
 *              If the current record is empty its deleted by this
 *              routine.
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    true is current record is deleted by this routine.
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	7/28/95	Initial Revision
 *			gap	8/01/00	add attention manager support
 *
 ***********************************************************************/
Boolean ClearEditState (void)
{
	UInt16 recordNum;
	Boolean empty;
	Boolean hasAlarm;
	MemHandle recordH;
	ApptDBRecordType apptRec;

	if ( ! ItemSelected)
		{
		CurrentRecord = noRecordSelected;
		return (false);
		}
	
	recordNum = CurrentRecord;

	// Clear the global variables that keep track of the edit state of the
	// current record.
	ItemSelected = false;
	CurrentRecord = noRecordSelected;
	DayEditPosition = 0;
	DayEditSelectionLength = 0;
	
	// If the description field is empty there is no note, delete
	// the record.
	ApptGetRecord (ApptDB, recordNum, &apptRec, &recordH);
	hasAlarm = (apptRec.alarm != NULL);	
	empty = true;
	if (apptRec.description && *apptRec.description)
		empty = false;
	else if (apptRec.note && *apptRec.note)
		empty = false;
	MemHandleUnlock (recordH);


	if (empty)
		{
		UInt32		alarmRef;	// Ignored. Needed for AlarmGetTrigger()

		// if the event to be delete had an alarm, be sure to remove it
		// from the posted alarm queue before the event is deleted.
		if (hasAlarm)
			DeleteAlarmIfPosted(recordNum);
		
		// If the record was not modified, and the description and 
		// note fields are empty, remove the record from the database.
		// This can occur when a new empty record is deleted.
		if (RecordDirty)
			{
			DmDeleteRecord (ApptDB, recordNum);
			DmMoveRecord (ApptDB, recordNum, DmNumRecords (ApptDB));
			}
		else
			DmRemoveRecord (ApptDB, recordNum);
		
		// If the appointment had the currently scheduled alarm, reschedule the next alarm
		if (hasAlarm)
			{
			UInt32 alarmTrigger = AlarmGetTrigger (&alarmRef);
			
			if (alarmTrigger && (alarmTrigger == ApptGetAlarmTime (&apptRec, TimGetSeconds(), true)))
				{
				RescheduleAlarms (ApptDB);
				}
			}

		return (true);
		}

	return (false);
}


// Branch island to get to the glue code, linked in first.

Char* DateParamString(const Char* inTemplate, const Char* param0,
			const Char* param1, const Char* param2, const Char* param3)
{
	return(TxtParamString(inTemplate, param0, param1, param2, param3));
}


#pragma mark ----------------
/***********************************************************************
 *
 * FUNCTION:    PilotMain
 *
 * DESCRIPTION: This is the main entry point for the Datebook
 *              application.
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	6/12/95	Initial Revision
 *			vmk	10/22/97	Moved MIDI db creation to general panel
 *			art	1/7/98	Save current record before receiving a beamed record
 *			rbb	4/22/99	Moved code to link w/ 16-bit jumps
 *			rbb	6/20/99	Removed multi-segment workaround
 *			jmp	10/02/99 Made the support for the sysAppLaunchCmdExgReceiveData
 *								launch code more like its counterparts in Address,
 *								Memo, and ToDo.
 *			jmp	10/18/99	Note that Datebook doesn't attempt to create an empty
 *								database if a default ("demo") database doesn't exist.
 *			jmp	11/04/99	Eliminate extraneous FrmSaveAllForms() call from sysAppLaunchCmdExgAskUser
 *								since it was already being done in sysAppLaunchCmdExgReceiveData if
 *								the user affirmed sysAppLaunchCmdExgAskUser.  Also, in sysAppLaunchCmdExgReceiveData
 *								prevent call FrmSaveAllForms() if we're being call back through
 *								PhoneNumberLookup() as the two tasks are incompatible with each other.
 *			rbb	11/12/99	Added recentFormFeature to pick default view on launch
 *
 ***********************************************************************/
UInt32	PilotMain (UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
{
	UInt16 error;
	UInt32 defaultForm;
   DmOpenRef dbP;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?