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

📄 dateweek.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************
 *
 * Copyright (c) 1995-2003 PalmSource, Inc. All rights reserved.
 *
 * File: DateWeek.c
 *
 * Release: Palm OS 5 SDK (68K) R3.
 *
 * Description:
 *	  This is the Datebook application's week view module.
 *
 *****************************************************************************/

#include <PalmOS.h>

#include <PalmUtils.h>

#include "DateLunar.h"	// For DateSupportsLunarCalendar, etc.
#include "Datebook.h"

//DOLATER - peter: remove this once a choice is made.
#define UNMASK_PRIVATE_RECORDS_IN_WEEK_VIEW		1

/***********************************************************************
 *
 *	Global variables
 *
 ***********************************************************************/

extern privateRecordViewEnum	CurrentRecordVisualStatus;	// applies to current record
extern privateRecordViewEnum	PrivateRecordVisualStatus;	// applies to all other records

//	WeekView globals:
static MemHandle				WeekObjectH;				//	The currently active
																	//	week

static CustomPatternType	regAppt = {0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55};
										//	50% gray pattern
static CustomPatternType	overLapAppt = {0x88, 0x44, 0x22, 0x11, 0x88, 0x44, 0x22, 0x11};
										//	Diagonal stripes
static FontID					OrigFont;


/***********************************************************************
 *
 *	Internal Constants
 *
 ***********************************************************************/


//	WeekView/Day object constants
#define weekViewDayHMargin					4		//	This is the horizontal space
 															//	between the edge of the day's
 															//	bounds and the visible event
 															//	bar.

#define weekViewTimeDisplayWidth			25		//	Width of column of times
#define timeHMargin							2		//	Horiz margin between times
															//	& first day bar.
#define weekHMargin							2		//	Horiz margin between days
															//	and right edge of screen.
#define weekViewDayDisplayHeight			12		//	Height of day labels at top
															//	of view.
#define weekViewDateDisplayHeight		13		//	Height of date labels under
															//	day labels at top of view.
#define weekViewEventFrameWidth			3		//	Width of frame around

#define weekViewScrollInterval			4		//	Scroll interval, in hours.
															//	Must be >= 1.
#define weekViewNumDispHours				11		//	Number of hours that we display
															//	on one screenful of data.
#define weekViewHourDisplayInterval		2		//	Used for displaying the time
															//	bar.
															
#define dataMarkHMargin						4		//	Horizontal margins around
															//	data indicators.
#define dataMarkVMargin						2
#define outOfRangeDay						0		//	illegal date.
 
#define weekDescMarginX						3		// Margin in popup desc
#define weekDescMarginY						2		// Margin in popup desc

#define moveThreshold						8		// Number of pixels to drag an 
															// event before it starts moving

#define weekDescDisplayTicks				200	// number of tick to display the
															// description popup 
#define weekDescUnmaskedDisplayTicks	500	// number of tick to display the
															// description popup for unmasked
															// events
/***********************************************************************
 *
 *	Internal Structutes
 *
 ***********************************************************************/

//	These structures are used by the WeekView of the DateBook
typedef struct
	{
	RectangleType			bounds;
	DateType					date;					//	If the 'day' field is set to
														//	'outOfRangeDay', this day is
														//	outside the allowable system range
														//	and should not be drawn.
	UInt8						dayOfWeek;
	UInt8						reserved;
	MemHandle				apptsH;				//	Use ApptInfoPtr to examine
	UInt16					numAppts;
	UInt16					firstEventHour;
	UInt16					lastEventHour;		//	The limits of the events which
														//	exist on this day.  Meaningless
														//	if there are no appts.
	} DayType;
	
typedef struct
	{
	RectangleType			bounds;
	UInt16					startHour;			//	first currently displayed hour
	UInt16					endHour;				//	last currently displayed hour
	DayType					days[daysInWeek];
	DateType					startDate;			//	Start date of week
	UInt16					firstEventHour;	//	Hour of earliest event
														//	during the current week.
	UInt16					lastEventHour;		//	Hour of latest event
														//	during the current week.
	UInt16					hourHeight;			//	Height, in pixels, of one
														//	hour of time in a day bar.
	Int32						descTick;			// tick count when the popup 
														// description was displayed.
	WinHandle				behindDesc;			// bits behind popup description.
	WinHandle				behindHighlight;	// bits behind selection highlighting

	} WeekType;
	
typedef WeekType * WeekPtr;

/***********************************************************************
 *
 *	Internal Functions
 *
 ***********************************************************************/
static void WeekViewDrawTimes (Int16 startYPos, UInt16 startHour, UInt16 endHour,
										 UInt16 hourHeight);
static void WeekViewFree (void);
static void WeekViewInit (FormPtr frm);
static void WeekViewInitDays (FormPtr frm);
static void WeekViewDrawDays (void);
static void WeekViewDraw (FormPtr frm);
static void WeekEraseDescription (Boolean eraseIt);
static void WeekViewUpdateDisplay (UInt16 updateCode);
 
// DOLATER ??? - move to time manager.
/***********************************************************************
 *
 * FUNCTION:    TimeDifference
 *
 * DESCRIPTION: Subtract pTime2 from pTime1 and place the result in
 *					 pTimeDiff.
 *
 *					 Note that TimeType is now unsigned so this doesn't
 *					 work for negative times (which no longer exist!).
 *
 * PARAMETERS:  pTime1   - pointer to HMSTime
 *              pTime2   - pointer to HMSTime
 *              pTimeDiff- pointer to HMSTime
 *
 * RETURNED:	 pTimeDiff is set to pTime1 - pTime2.
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			roger	12/2/94	Initial Revision
 *
 ***********************************************************************/

static void TimeDifference (TimePtr pTime1, TimePtr pTime2, TimePtr pTimeDiff)
	{
	pTimeDiff->hours = pTime1->hours - pTime2->hours;

	if (pTime1->minutes < pTime2->minutes)
		{
		pTimeDiff->minutes = pTime1->minutes + hoursInMinutes - pTime2->minutes;
		pTimeDiff->hours--;
		}
	else
		pTimeDiff->minutes = pTime1->minutes - pTime2->minutes;
	
	}

/***********************************************************************
 *
 * FUNCTION:    FirstDayOfYear
 *
 * DESCRIPTION: Return the number of day from 1/1/1904 of the first day 
 *              of the year passed.
 *
 *					 The first day of the year is always a Monday.  The rule 
 *					 for determining the first day of the year is:
 *				
 *					 New Years Day	First Day of the Year
 *					 ------------	---------------------
 *					 Monday			Monday Jan 1
 *					 Tuesday			Monday Dec 31
 *					 Wednesday		Monday Dec 30
 *					 Thursday		Monday Dec 29
 *					 Friday			Monday Jan 4 
 *					 Saturday		Monday Jan 3 
 *					 Sunday			Monday Jan 2
 *
 * PARAMETERS:	 year  - year (1904-2031)
 *
 * RETURNED:	 number of days since 1/1/1904
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	4/4/96	Initial Revision
 *
 ***********************************************************************/
static UInt32 FirstDayOfYear (UInt16 year)
{
	UInt32 days;
	UInt16 dayOfWeek;
	DateType date;
	
	// Get days to January 1st of the year passed.
	date.day = 1;
	date.month = 1;
	date.year = year - firstYear;
	days = DateToDays (date);
	
	dayOfWeek = DayOfWeek (1, 1, year);

	// Move to monday.
	days++;
	days -= dayOfWeek;

	
	if (dayOfWeek >= friday)
		days += daysInWeek;
		
	return (days);
}


/***********************************************************************
 *
 * FUNCTION:    GetWeekNumber
 *
 * DESCRIPTION: Calculate the week number of the specified date.
 *
 * PARAMETERS:	 month - month (1-12)
 *              day   - day (1-31)
 *              year  - year (1904-2031)
 *
 * RETURNED:	 week number (1-53)
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	4/4/96	Initial Revision
 *
 ***********************************************************************/
static UInt16 GetWeekNumber (UInt16 month, UInt16 day, UInt16 year)
	{
	UInt16 dow;
	UInt16 week;
	UInt32 days;
	UInt32 firstOfYear;
	UInt32 firstOfNextYear;
	DateType date;

	// Calculate the julian date of Monday in the same week as the 
	// specified date.
	date.day = day;
	date.month = month;
	date.year = year - firstYear;
	days = DateToDays (date);

	// Adjust the day of the week by the preference setting for the first day
	// of the week.
	dow = (DayOfWeek (month, day, year) - StartDayOfWeek + daysInWeek) 
				% daysInWeek;

	if (monday < StartDayOfWeek)
		days -= (Int16)dow - (monday + daysInWeek - StartDayOfWeek);
	else		
		days -= (Int16)dow - (monday - (Int16)StartDayOfWeek);


	firstOfYear = FirstDayOfYear (year);
	
	if (days < firstOfYear)
		{
		// The date passed is in a week that is part of the prior 
		//	year, so get the start of the prior year.
		if (year > firstYear)
			firstOfYear = FirstDayOfYear (--year);
		}
	else
		{
		// Make sure the date passed is not in a week that in part
		// of next year.
		if (year < lastYear)
			{  
			firstOfNextYear = FirstDayOfYear (year + 1);
			if (days == firstOfNextYear)
				firstOfYear = firstOfNextYear;
			}
		}
	
	week = ((Int16)(days - firstOfYear)) / daysInWeek + 1;		// one base
	
	return (week);
	}
	

/***********************************************************************
 *
 * FUNCTION:    WeekViewNewAppointment
 *
 * DESCRIPTION:	This routine create a new apointment.  It's called
 *                when the user selects an empty time slot.
 *
 * PARAMETERS:		startTime - start time of the new appointment
 *                endTime   - end time of the new appointment
 *
 * RETURNED:		nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	9/25/95	Initial Revision
 *       ryw   2/18/00  Added cast to satisfy const cstring checking, should be safe
 *
 ***********************************************************************/
static void WeekViewNewAppointment (TimePtr startTime, TimePtr endTime)
{
	Err error;
	UInt16 recordNum;
	ApptDBRecordType newAppt;
	ApptDateTimeType when;
	
	// Create a new appointment on the current day.
	MemSet (&newAppt, sizeof (newAppt), 0);

	when.startTime = *startTime;
	when.endTime = *endTime;
	if (TimeToInt(when.endTime) > apptMaxEndTime)
		TimeToInt (when.endTime) = apptMaxEndTime;
	when.date = Date;
	newAppt.when = &when;
	newAppt.description = (char *)""; 
	if (AlarmPreset.advance != apptNoAlarm)
		newAppt.alarm = &AlarmPreset;		

	error = ApptNewRecord (ApptDB, &newAppt, &recordNum);
	
	if (! error)
		{
		CurrentRecord = recordNum;
		ItemSelected = true;
		}

	// Display an alert that indicates that the new record could 
	// not be created.
	if (error)
		{
		// DOLATER - Add alert here
		}
}


/***********************************************************************
 *
 * FUNCTION:    WeekViewUpdateScrollers
 *
 * DESCRIPTION:	This routine draws or erases the Week View scroll arrow
 *						buttons depending on whether there is more data to be
 *						displayed in either direction.
 *
 * PARAMETERS:		frm - pointer to the Week View form.
 *
 * RETURNED:		nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			kcr	7/31/95	Initial Revision
 *			kcr	9/20/95	convert to use FrmUpdateScrollers
 *
 ***********************************************************************/
static void WeekViewUpdateScrollers (FormPtr frm)
	{
	WeekType		*week;
	UInt16 upIndex;
	UInt16 downIndex;
	Boolean scrollableUp;
	Boolean scrollableDown;
	
	week = MemHandleLock (WeekObjectH);

	scrollableUp = (week->startHour > week->firstEventHour);
	scrollableDown = (week->endHour < week->lastEventHour);
	upIndex = FrmGetObjectIndex (frm, WeekUpButton);
	downIndex = FrmGetObjectIndex (frm,WeekDownButton);
	FrmUpdateScrollers (frm, upIndex, downIndex, scrollableUp, scrollableDown);
		
	MemPtrUnlock(week);

⌨️ 快捷键说明

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