⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datealarm.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
字号:
/******************************************************************************
 *
 * Copyright (c) 1995-2003 PalmSource, Inc. All rights reserved.
 *
 * File: DateAlarm.c
 *
 * Release: Palm OS 5 SDK (68K) R3.
 *
 * Description:
 *	  This module contains the routines that handle alarms.
 *
 *****************************************************************************/

#include <PalmOS.h>
#include <AlarmMgr.h>
#include <FeatureMgr.h>

#include <PalmUtils.h>

#include "Datebook.h"

extern ECApptDBValidate (DmOpenRef dbP);



/***********************************************************************
 *
 *	Internal Constants
 *
 ***********************************************************************/
#define alarmDescSeparatorY				9		// whitespace between title and description
#define alarmDetailDescHTextOffset		37
#define alarmDetailDescYTextOffset		4
#define alarmDetailDescMaxLine			4
#define alarmListDescMaxLine				1
#define alarmListDescriptionOffset		5

#define alarmPaddingSeconds				3		// alarms will never trigger more than 3 seconds early


/***********************************************************************
 *
 * FUNCTION:		FindRecordByID
 *
 * DESCRIPTION:	As DmFindRecordByID does not take into account the deleted
 *						any time we want to proccess an attention callback DmQueryRecord
 *						must alsp be called to determine if the unique ID is one
 *						the app needs to take action on.  I have combined both routines
 *						in this call to be sure both are done in all instances that the
 *						record number is obtained via the uniqueID.
 *						THIS MAY BE CALLED AT INTERRUPT LEVEL, SO DONT USE GLOBALS!!
 *
 * PARAMETERS:		dbP 			- the note pad database
 * 					uniqueID		- the uniqueID of the note
 *						recordNum	- the record number of the note				
 *
 * RETURNED:		err			- 0 if we get a valid "active" (ie not deleted) refnum
 *										- dmErrUniqueIDNotFound if the id is not found or if the
 *										  record is not currently usable  (ie it is marked deleted)
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			gap	09/13/00	Initial Revision
 *
 ***********************************************************************/
Err FindRecordByID (DmOpenRef dbP, UInt32 uniqueID, UInt16 * recordNum)
{
	Err			err;
	MemHandle	recordH;

	// determine if the uniqueID exists in the specified DB
	err = DmFindRecordByID (dbP, uniqueID, recordNum);
	if (err) return err;
	
	// if the record is there, be sure if is one we can access
	recordH = DmQueryRecord (dbP, *recordNum);
	if (!recordH) return dmErrUniqueIDNotFound;
	
	return 0;
}


/***********************************************************************
 *
 * FUNCTION:    CondensedTimeToAscii
 *
 * DESCRIPTION:  Convert the time passed to an ascii string.
 *
 * PARAMETERS:  hours    - hours (0-23)
 *					 minutes	 - minutes (0-59)
 *					 timeFormat - how to format the time string
 *					 pString  - pointer to string which gets the result. The
 *									string must be of length timeStringLength
 *
 * RETURNED:	 pointer to the text of the current selection
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			roger	12/2/94	Initial Revision
 *			roger 2/28/95	Changed and made available to system
 *			roger 8/5/96	Added new tfComma24h format
 *
 ***********************************************************************/
 /*
static void CondensedTimeToAscii(UInt8 hours, UInt8 minutes, TimeFormatType timeFormat, Char * pString)
{
	char t;
	
#if ERROR_CHECK_LEVEL == ERROR_CHECK_FULL
	// Fill up the destination as much as allowed with a value to reveal errors.
	MemSet(pString, timeStringLength, 0xfe);	
#endif
	
	t = hours;
	if ( (timeFormat == tfColon24h) || (timeFormat == tfDot24h) ||
		  (timeFormat == tfHours24h) || (timeFormat == tfComma24h) )
		{
		if (t >= 20)
			{
			t -= 20;
			*pString++ = '2';
			}
		}
	else
		{
		t %= 12;
	
		if (t == 0)
			{
			t = 2;
			*pString++ = '1';
			}
		}

	if (t >= 10)
		{
		t -= 10;
		*pString++ = '1';
		}
	*pString++ = '0' + t;


	// Now add the minutes
	if ( (timeFormat != tfHoursAMPM) && (timeFormat != tfHours24h) )
		{
		*pString++ = TimeSeparator(timeFormat);
	
		// Translate minutes in to text characters:
		*pString++ = '0' + minutes / 10;
		*pString++ = '0' + minutes % 10;
		}
			
	
	if ( (timeFormat == tfColonAMPM) || (timeFormat == tfDotAMPM) ||
		(timeFormat == tfHoursAMPM))
		{
		if (hours >= 12)
			*pString++ = 'p';
		else
			*pString++ = 'a';
		*pString++ = 'm';
		}

	*pString++ = '\0';
}
*/


#pragma mark -
/***********************************************************************
 *
 * FUNCTION:		DeleteAlarm
 *
 * DESCRIPTION:	Deletes the specified alarm from the attention manager
 *						queue. 
 *						THIS MAY BE CALLED AT INTERRUPT LEVEL, SO DONT USE GLOBALS!!
 *
 * PARAMETERS:		uniqueID	- the uniqueID of the event
 *
 * RETURNED:		nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			gap	07/27/00	Initial Revision
 *
 ***********************************************************************/
static void DeleteAlarm (UInt32 uniqueID)
{
	UInt16 		cardNo;
	LocalID 		dbID;
	DmSearchStateType searchInfo;

	DmGetNextDatabaseByTypeCreator (true, &searchInfo, sysFileTApplication, sysFileCDatebook, true, &cardNo, &dbID);
	AttnForgetIt(cardNo, dbID, uniqueID);
}


/***********************************************************************
 *
 * FUNCTION:		DrawListAlarm
 *
 * DESCRIPTION:	Draws the alarm info in attention manager list view. 
 *						THIS MAY BE CALLED AT INTERRUPT LEVEL, SO DONT USE GLOBALS!!
 *
 * PARAMETERS:		eventTime	- pointer to time of event 
 *						duration		- pointer to duration of event 
 *						untimed		- specifies if this is an untimed event
 *						description	- pointer to the text to be displayed to describe event
 *						paramsPtr	- pointer to attention manager structure containing info
 *										  as to where to draw			
 *
 * RETURNED:		nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			gap	10/04/00	Initial Revision
 *			CS		11/14/00	Use PrefGetPreference instead of PrefGetPreferences.
 *
 ***********************************************************************/
static void DrawListAlarm (UInt32 eventTime, UInt16 duration, char* description, Boolean untimed, AttnCommandArgsType *paramsPtr)
{
	Char 							dateStr[longDateStrLength];
	Char							timeStr [timeStringLength];
 	UInt16						lineCount = 0;
 	UInt16						length;
 	Int16							descLen;
	Int16							descFitWidth;
	Int16							descFitLen;
	UInt16						maxWidth;
 	Int16							x, y, iconOffset;
	FontID						curFont;
	MemHandle					resH;
	Char*							resP;
	Char*							ptr;
	DateTimeType 				startDateTime, endDateTime, today;
	DateFormatType				dateFormat;
	TimeFormatType				timeFormat;
	Boolean						fit;
 	Char							chr;
	MemHandle					smallIconH;
	BitmapPtr					smallIconP;


	// Get the date and time formats.
	dateFormat = (DateFormatType)PrefGetPreference(prefDateFormat);
	timeFormat = (TimeFormatType)PrefGetPreference(prefTimeFormat);

	// Compute the maximum width of a line of the description.
	maxWidth = paramsPtr->drawList.bounds.extent.x;

	// Set the font used to draw the alarm info
	curFont = FntSetFont (stdFont);

	y = paramsPtr->drawList.bounds.topLeft.y;
	x = paramsPtr->drawList.bounds.topLeft.x;

	//draw the application's small icon
	smallIconH = DmGet1Resource(iconType, 1001);
	if (smallIconH) 
		{
		Coord smallIconWidth;
			
		smallIconP = (BitmapPtr)(MemHandleLock(smallIconH));
		BmpGetDimensions(smallIconP, &smallIconWidth, NULL /* heightP */, NULL /* rowBytesP */);
		iconOffset = (kAttnListMaxIconWidth - smallIconWidth)/2;
		WinDrawBitmap(smallIconP, x+iconOffset, y);
		MemHandleUnlock (smallIconH);
		DmReleaseResource(smallIconH);
		}
	
	x += kAttnListTextOffset;

	TimSecondsToDateTime (eventTime, &startDateTime);	
	
	// draw the time information for the event if the event has a time and the duration is > 0.
	if (!untimed)
		{
		// Draw the event's start time
		TimeToAscii (startDateTime.hour, startDateTime.minute, timeFormat, timeStr);
	
		WinDrawChars (timeStr, StrLen (timeStr), x, y);
		x += FntCharsWidth (timeStr, StrLen (timeStr));

		// draw the event's end time if its duration is > 0
		if (duration > 0)
			{
			x += (FntCharWidth(spaceChr) / 2);
			chr = '-';
			WinDrawChars (&chr, 1, x, y);
			x += FntCharWidth (chr) + (FntCharWidth(spaceChr) / 2);
		
			TimSecondsToDateTime (eventTime + (duration * minutesInSeconds), &endDateTime);
			TimeToAscii (endDateTime.hour, endDateTime.minute, timeFormat, timeStr);
			WinDrawChars (timeStr, StrLen (timeStr), x, y);
			x += FntCharsWidth (timeStr, StrLen (timeStr)) + FntCharWidth(spaceChr);
			}
		else
			x += FntCharWidth (spaceChr);
		}


	// Draw the event's date
	// If the event occurs today, draw the 
	TimSecondsToDateTime (TimGetSeconds(), &today);	

	if ( (today.day == startDateTime.day) && (today.month == startDateTime.month) && (today.year == startDateTime.year))
		{
		resH = DmGetResource (strRsc, alarmTodayStrID);
		resP = MemHandleLock(resH);
		WinDrawChars (resP, StrLen (resP), x, y);
		MemPtrUnlock (resP);
		}
	else
		{
		DateToAscii(startDateTime.month, startDateTime.day, startDateTime.year, dateFormat, dateStr);
		WinDrawChars (dateStr, StrLen (dateStr), x, y);
		}
	
	// Draw the event's description.
	x = paramsPtr->drawList.bounds.topLeft.x + kAttnListTextOffset;
	y += FntLineHeight();
	maxWidth = paramsPtr->drawList.bounds.extent.x - kAttnListTextOffset;
	
	ptr = description;
	descLen = StrLen(ptr);

	while(descLen)
		{
		descFitWidth = maxWidth;
		descFitLen = descLen;
		
		// Calculate how many characters will fit in the window bounds
		FntCharsInWidth (ptr, &descFitWidth, &descFitLen, &fit);
		if (!descFitLen)
			break;
			
		// Calculate the number of characters in full words that will fit in the bounds
		length = FldWordWrap(ptr, maxWidth);
		
		// Need to display the minimum of the two as FldWordWrap includes carriage returns, tabs, etc.
		descFitLen = min(descFitLen, length);

		if (++lineCount >= alarmListDescMaxLine) {
			if (descLen != descFitLen)
				descFitLen = descLen;
				
			// DOLATER ゥ

⌨️ 快捷键说明

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