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

📄 dateweek.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
📖 第 1 页 / 共 5 页
字号:
 *						The screen is scrolled on weekViewScrollInterval if
 *						byPage is FALSE, and by weekViewNumDispHours if
 *						byPage is TRUE, in the specified direction.
 *
 * PARAMETERS:	WinDirectionType		direction - winUp or dowm
 *					Boolean					byPage - TRUE if scrolling by page, FALSE
 *												if scrolling by weekViewScrollInterval
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			kcr	8/7/95	Initial Revision
 *			kcr	8/8/95	added page scrolling
 *			kcr	8/21/95	scroll to even intervals when not scrolling byPage
 *			grant	1/27/99	scroll by an even number of hours - otherwise the
 *								checkerboard fill patterns can get out of sync
 *			gap	11/14/00 fix checkin above to not allow the start time to 
 *								be decremented below 0
 *
 ***********************************************************************/
static void WeekViewScroll (WinDirectionType direction, Boolean byPage)
	{
	int					interval;
	RectangleType		r, vacated, origClip;
	Int16					lineYPos;
	WeekType				*week;
	UInt16				scrollDist;
	UInt16				dispStartHour;
	Boolean				forceFullRedraw = false;
	
	week = MemHandleLock (WeekObjectH);
	
	if (byPage)
		interval = weekViewNumDispHours;
	else
		interval = weekViewScrollInterval;
		
	//	Adjust week's displayed hour range in the proper direction
	if (direction == winUp)
		{
		if (byPage)
			scrollDist = weekViewNumDispHours;
		else
			scrollDist = week->startHour -
							 ((((week->startHour - interval - 1) / interval) + 1) *
							  interval);
		if ((week->startHour - week->firstEventHour) < scrollDist)
			scrollDist = week->startHour - week->firstEventHour;

		// only scroll by an even number of hours (otherwise the event fill
		// pattern gets out of sync)
		if (scrollDist % 2 != 0)
			{
			scrollDist++;
			
			// Don't scroll up (decrement) more than startHour. This field is an
			// unsigned int so wrapping around to the 655xx values is not desired. 
			// if the scroll distance is odd, just force a full update of the grid
			// area to keep the patterns in sync.   
			if (scrollDist > week->startHour)
				{
				scrollDist = week->startHour;
				forceFullRedraw = (scrollDist % 2 != 0);
				}
			}

		week->startHour -= scrollDist;
		week->endHour -= scrollDist;
		}
	else	//	winDown
		{
		if (byPage)
			scrollDist = weekViewNumDispHours;
		else
			scrollDist = (((week->startHour / interval) + 1) * interval) - 
							 week->startHour;
		if ((week->lastEventHour - week->endHour) < scrollDist)
			scrollDist = week->lastEventHour - week->endHour;

		// only scroll by an even number of hours (otherwise the event fill
		// pattern gets out of sync)
		if (scrollDist % 2 != 0)
			{
			scrollDist++;
			}

		week->startHour += scrollDist;
		week->endHour += scrollDist;
		}

	//	Redraw the hour markers:
	//	Determine where start of backround is:	
 	lineYPos = week->bounds.topLeft.y +
 						 weekViewDayDisplayHeight +
 						 weekViewDateDisplayHeight;
 	dispStartHour = week->startHour;

 	while ((dispStartHour % weekViewHourDisplayInterval) != 0)
 		{	//	Display starts on an odd hour
 		lineYPos += week->hourHeight;
 		dispStartHour++;
 		}

 	//	Draw times - vertically centered on background lines; 
 	//	horizontally centered in space between left edge of view and
 	//	left end of lines.  Erase background first.
	r = week->bounds;
	r.extent.x = weekViewTimeDisplayWidth;
	WinEraseRectangle (&r, 0);
 	WeekViewDrawTimes (lineYPos, dispStartHour, week->endHour, week->hourHeight);	

	//	We only want to scroll the 'event bar' area of the screen.
	//	Shrink the vertical size by 1 pix on top to keep the frame
	//	edges intact.
	r = week->bounds;
	r.topLeft.y += (weekViewDayDisplayHeight + weekViewDateDisplayHeight +1);
	r.extent.y = week->hourHeight*weekViewNumDispHours -1;
	r.topLeft.x += weekViewTimeDisplayWidth + 1;
	r.extent.x = r.extent.x - weekViewTimeDisplayWidth - 2;

	//	The actual scrolling dirty-work:
	// Normally the scroll distance will be even so that the fill pattern will not
	// be out of alignment when updating the vacated area of the screen after scrolling
	// the view.  Occasionally, when scrolling up, the scroll will be odd in order to pin
	// the minimum start hour to 0.  When this happens, erase & update the entire grid
	// area so that the fill pattern will remain in sync.
	if (forceFullRedraw)
		{
		vacated = r;
		}
	else
		{
		if (direction == winUp)
			WinScrollRectangle (&r, winDown, scrollDist*week->hourHeight, &vacated);
		else
			WinScrollRectangle (&r, winUp, scrollDist*week->hourHeight, &vacated);
		}
		
	// update the "vacated" area
	WinEraseRectangle (&vacated, 0);
	WinGetClip (&origClip);
	WinSetClip (&vacated);
	WeekViewDraw (FrmGetActiveForm ());
	WeekViewDrawDays ();
	WinSetClip (&origClip);
	WeekViewDrawDataMarks ();

	WeekViewUpdateScrollers (FrmGetActiveForm());

	MemPtrUnlock(week);
	}	//	end of WeekViewScroll


/***********************************************************************
 *
 * FUNCTION:    WeekViewGoToWeek
 *
 * DESCRIPTION:	This routine moves the Week View to the week
 *						including the current setting of Date.  It is assumed
 *						that the week view is already winUp; it must be erased,
 *						reinitialized, and redrawn.
 *
 * PARAMETERS:  	nothing
 *
 * RETURNED:    	nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			kcr	8/21/95	Initial Revision
 *			kcr	9/19/95	removed date calc.  Must be done by caller.
 *
 ***********************************************************************/
static void WeekViewGoToWeek (void)
	{
	WeekType				*week;

	WeekViewFree ();
	WeekViewInit (FrmGetActiveForm ());

	//	Erase the old week view before drawing the new one.
	week = MemHandleLock (WeekObjectH);
	WinEraseRectangle (&(week->bounds), 0);
	WeekViewDraw (FrmGetActiveForm ());

	WeekViewInitDays (FrmGetActiveForm ());
	WeekViewDrawDays ();
	WeekViewDrawDataMarks ();

	MemPtrUnlock(week);
	}	//	end of WeekViewGoToWeek
	

/***********************************************************************
 *
 * FUNCTION:    WeekViewDayInit
 *
 * DESCRIPTION:	This routine initializes a passed DayType structure.
 *						All fields of the DayType struct are filled in and
 *						the week->firstEventHour and week->lastEventHour vars are
 *						maintained.
 *
 * PARAMETERS:		DayType				*day - the structure to init.
 *						UInt8		dayOfWeek - matches date
 *						RectanglePtr		bounds
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date			Description
 *			----	----			-----------
 *			kcr	7/28/95		Initial Revision
 *			kcr	10/3/95		calc day's event range, as well as week's.
 *			kcr	10/12/95		don't calc data if date is out of range.
 *			kcr	11/13/95		remove date param; dates are set during week init
 *
 ***********************************************************************/
 static void WeekViewDayInit (DayType *day, UInt8 dayOfWeek,
 										RectanglePtr bounds,
 										UInt16 *firstEventHour, UInt16 *lastEventHour,
 										MemHandle apptsH, UInt16 numAppts)
 	{
 	ApptInfoPtr				appts;
 	int						i;

 	//	Load day bounds
 	day->bounds = *bounds;

 	//	Load the appt list
 	if (day->date.day != outOfRangeDay)
 		{
	 	day->apptsH = apptsH;
	 	day->numAppts = numAppts;
	 	day->dayOfWeek = dayOfWeek;
	 	}
	else	//	Non-displayable date.
		{
		day->apptsH = 0;
		day->numAppts = 0;
		day->dayOfWeek = 0;
		}
 	day->firstEventHour = 24;
 	day->lastEventHour = 0;

 	//	Stretch the bounds of the scrolling range if there are any events
 	//	outside the current range.  This must be performed for both
 	//	the day and the week.
	if (day->numAppts > 0)
		appts = MemHandleLock (day->apptsH);
 	for (i = 0; i < day->numAppts; i++)
 		{
 		if ((appts[i].startTime.hours != (UInt8) apptNoTime) &&
 			 (appts[i].startTime.hours < (*firstEventHour)))
 			{
 			//	Round winDown to the nearest hour <= start of appt.
 			(*firstEventHour) = appts[i].startTime.hours;
 			day->firstEventHour = appts[i].startTime.hours;
 			}
 		else if ((appts[i].startTime.hours != (UInt8) apptNoTime) &&
					(appts[i].startTime.hours < day->firstEventHour))
 			day->firstEventHour = appts[i].startTime.hours;


 		if ((appts[i].endTime.hours != (UInt8) apptNoTime) &&
 			 (appts[i].endTime.hours > (*lastEventHour) ||
 			  (appts[i].endTime.hours == (*lastEventHour) &&
 			   appts[i].endTime.minutes != 0)))
 			{
 			//	Round winUp to the next hour >= end of the appt.
 			(*lastEventHour) = appts[i].endTime.hours;
 			if (appts[i].endTime.minutes != 0)
 				(*lastEventHour)++;
 			day->lastEventHour = appts[i].endTime.hours;
 			if (appts[i].endTime.minutes != 0)
 				day->lastEventHour++;
 			}

 		else if ((appts[i].endTime.hours != (UInt8) apptNoTime) &&
 					(appts[i].endTime.hours > day->lastEventHour ||
 					 (appts[i].endTime.hours == day->lastEventHour &&
 					  appts[i].endTime.minutes != 0)))
 			{
 			//	Round winUp to the next hour >= end of the appt.
 			day->lastEventHour = appts[i].endTime.hours;
 			if (appts[i].endTime.minutes != 0)
 				day->lastEventHour++;
 			}
 		}
 	if (day->numAppts > 0)
 		MemPtrUnlock(appts);

 	}	//	end of WeekViewDayInit


/***********************************************************************
 *
 * FUNCTION:    WeekViewDayClose
 *
 * DESCRIPTION:	This routine frees all allocatd memory involved in
 *						a DayType structure.  It is generally called when a week
 *						is being torn winDown.
 *
 * PARAMETERS:		DayType				*day
 *
 * RETURNED:    	nothing
 *
 * REVISION HISTORY:
 *			Name	Date			Description
 *			----	----			-----------
 *			kcr	8/9/95		Initial Revision
 *
 ***********************************************************************/
static void WeekViewDayClose (DayType *day)
 	{
 	if (day->numAppts != 0)
 		{
 		MemHandleFree (day->apptsH);
 		day->apptsH = 0;
 		}
 	}	//	end of WeekViewDayClose
 	

/***********************************************************************
 *
 * FUNCTION:    	WeekViewHoursToCoords
 *
 * DESCRIPTION:	Convert a time to a y-coordinate position, based on
 *						a starting hour.  'time' is assumed to be within the
 *						current hour display range.
 *
 * PARAMETERS:		TimeType				time - the time to convert
 *						UInt16					startHour - baseline of time to use
 *												as the zero-coordinate.
 *						UInt16					hourHeight - vertical size of an hour-long
 *												event.
 *
 * RETURNED:		UInt16					yPos - the difference, in y-coords,
 *												between startHour and time, based on
 *												week->hourHeight.
 *
 * REVISION HISTORY:
 *			Name	Date			Description
 *			----	----			-----------
 *			kcr	8/3/95		Initial Revision
 *
 ***********************************************************************/
static UInt16 WeekViewHoursToCoords(TimeType time, UInt16 startHour,
											 UInt16 hourHeight)
	{
	UInt16				yPos;
	
	yPos = (time.hours - startHour) * hourHeight;
	yPos += (time.minutes * hourHeight) / 60;
	return (yPos);
	}	//	end of WeekViewHoursToCoords


/***********************************************************************
 *
 * FUNCTION:    	WeekViewGetEventBounds
 *
 * DESCRIPTION:	Determine the top & bottom bounds of an event.
 *
 * PARAMETERS:		TimeType				startTime
 *						TimeType				endTime
 *						UInt16					startHour - start of time display
 *						UInt16					endHour - end of time display
 *						RectanglePtr		r - points to rectangle holding whole
 *													event bar's coords, including top &
 *													bottom of frame.
 *						UInt16					hourHeight - height, in pix, of an hour-
 *													long event.
 *
 * RETURNED:		nothing				y-coords of r have been adjusted so that
 *													frame around event (top & bottom) will
 *													include start & end times.
 *
 * REVISION HISTORY:
 *			Name	Date			Description
 *			----	----			-----------
 *			kcr	8/8/95		Initial Revision
 *
 ***********************************************************************/
static void WeekViewGetEventBounds(TimeType startTime, TimeType endTime,
											  UInt16 startHour, UInt16 endHour,
											  RectanglePtr r, UInt16 hourHeight)
	{
	Int16				startYOffset = 0;
	Int16				endYOffset;
	
	//	Determine start y coord, relative to top of r, inclusive of the
	//	startTime:
	if (startTime.hours > startHour ||
		 (startTime.hours == startHour &&
		  startTime.minutes != 0))
			{	//	Need to adjust start y coord.
			startYOffset = WeekViewHoursToCoords(startTime, startHour, hourHeight);
			r->topLeft.y += startYOffset;
			}
			
	//	Determine ending coord, relative to the top of the event bar,
	//	inclusive of the endTime:
	endYOffset = r->extent.y;
	if (endTime.hours < endHour)
		{	//	Need to shorten winUp end y-coord
		endYOffset = WeekViewHoursToCoords(endTime, startHour, hourHeight);
		endYOffset++;										//	Make the range inclusive

⌨️ 快捷键说明

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