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

📄 dateweek.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
📖 第 1 页 / 共 5 页
字号:
																//	of the endTime
		}

	r->extent.y = endYOffset - startYOffset;

	r->topLeft.y++;								//	Allow for top & bottom of frame
	r->extent.y -= 2;
	}	//	end of WeekViewGetEventBounds


/***********************************************************************
 *
 * FUNCTION:    	AdjustEventRight
 *
 * DESCRIPTION:	Shifts a full-width appt rect to the right side of 
 *						the event bar.  If the event bar is odd-width, we
 *						will put the smaller portion on the right.
 *
 * PARAMETERS:		RectanglePtr	event
 *
 * RETURNED:		Nothing; event is adjusted.
 *
 * REVISION HISTORY:
 *			Name	Date			Description
 *			----	----			-----------
 *			kcr	10/5/95		initial version
 *
 ***********************************************************************/
static void AdjustEventRight (RectanglePtr event)
	{
	Int16				oldWidth;

	//	Make the bar an extra pix narrower to accomodate it's frame.
	oldWidth = event->extent.x;
	event->extent.x = oldWidth / 2 - 1;
	event->topLeft.x += (oldWidth - event->extent.x);
	}	//	end of AdjustEventRight


/***********************************************************************
 *
 * FUNCTION:    	AdjustEventLeft
 *
 * DESCRIPTION:	Shifts a full-width appt rect to the left side of 
 *						the event bar.  If the event bar is odd-width, the
 *						smaller half of the bar goes on the right.
 *
 * PARAMETERS:		RectanglePtr	event
 *
 * RETURNED:		Nothing; event is adjusted.
 *
 * REVISION HISTORY:
 *			Name	Date			Description
 *			----	----			-----------
 *			kcr	10/5/95		initial version
 *
 ***********************************************************************/
static void AdjustEventLeft (RectanglePtr event)
	{
	//	Make the bar an extra pix narrower to accomodate the frame.
	event->extent.x = event->extent.x - (event->extent.x / 2) - 1;
	}	//	end of AdjustEventLeft


/***********************************************************************
 *
 * FUNCTION:    	UpdateEndTime
 *
 * DESCRIPTION:	Compares the passed time with the passed endTime.  If the
 *						time is later than the endTime, the endTime will be
 *						advanced to the earlier of either the time or the 
 *						timeLimit.
 *
 * PARAMETERS:		TimeType				*time - time to compare
 *						TimeType				*endTime - time to update
 *						UInt16					timeLimit - cannot advance *endTime
 *												past this hour value.
 *
 * RETURNED:		Nothing
 *
 * REVISION HISTORY:
 *			Name	Date			Description
 *			----	----			-----------
 *			kcr	10/5/95		initial version
 *
 ***********************************************************************/
static void UpdateEndTime (TimeType *time, TimeType *endTime,
									UInt16 timeLimit)
	{
	if (TimeToInt(*time) > TimeToInt (*endTime))
		{
		if (time->hours >= timeLimit)
			{
			endTime->hours = timeLimit;
			endTime->minutes = 0;
			}
		else
			{
			endTime->hours = time->hours;
			endTime->minutes = time->minutes;
			}
		}
	}	//	end of UpdateEndTime


/***********************************************************************
 *
 * FUNCTION:    	WeekViewDayDrawAppts
 *
 * DESCRIPTION:	Draws the passed appt list within the passed 
 *						RectangleType.  This should only be called when there
 *						is a non-0 number of events and a non-0 apptsH MemHandle.
 *
 * PARAMETERS:		MemHandle				apptsH - MemHandle of mem chunk containing
 *												the ApptInfoPtr (list).
 *						UInt16					numAppts - number of entries in apptsH.
 *						RectanglePtr		r - the day's current event bar; this
 *													includes the top & bottom frame area.
 *													The width is set correctly for frame
 *													drawing over the existing frame, or
 *													rect-filling within the existing frame.
 *						UInt16					startHour - first displayed hour of the
 *												event bar.
 *						UInt16					endHour - end of the event bar.
 *						UInt16					hourHeight - vertical size of an hour-long
 *													event.
 *
 * RETURNED:		Nothing
 *
 * REVISION HISTORY:
 *			Name	Date			Description
 *			----	----			-----------
 *			kcr	8/4/95		Initial Revision
 *			kcr	10/4/95		Draw overlapped events side-by-side
 *
 ***********************************************************************/
static void WeekViewDayDrawAppts (MemHandle apptsH, UInt16 numAppts,
											 RectanglePtr r, UInt16 startHour,
											 UInt16 endHour, UInt16 hourHeight)
	{
	ApptInfoPtr				appts;
	Boolean					overlapOnLeft;
	CustomPatternType		origPattern;
 	int						i;
 	RectangleType			apptRect;
 	TimeType					lastEndTimeLeft, lastEndTimeRight;

	appts = MemHandleLock (apptsH); 
	lastEndTimeLeft.hours = 0;
	lastEndTimeLeft.minutes = 0;
	lastEndTimeRight.hours = 0;
	lastEndTimeRight.minutes = 0;
	WinGetPattern(&origPattern);
	WinSetPattern(&regAppt);

	for (i = 0; i < numAppts; i++)
		{
		//	Only display timed appts.
		if (appts[i].startTime.hours == (UInt8) apptNoTime)
			continue;
		//	Don't display events which end <= startHour
		if (appts[i].endTime.hours < startHour ||
			 (appts[i].endTime.hours == startHour &&
			  appts[i].endTime.minutes == 0))
			continue;
		//	Don't display events which start >= endHour
		if (appts[i].startTime.hours >= endHour)
			continue;

		//	Check for overlap with previous appts on both sides:
		if (((appts[i].startTime.hours < lastEndTimeLeft.hours) ||
			  ((appts[i].startTime.hours == lastEndTimeLeft.hours) &&
			   (appts[i].startTime.minutes < lastEndTimeLeft.minutes))) &&
			 ((appts[i].startTime.hours < lastEndTimeRight.hours) ||
			  ((appts[i].startTime.hours == lastEndTimeRight.hours) &&
			   (appts[i].startTime.minutes < lastEndTimeRight.minutes))))
			{
			//	Overlapping appts need to be drawn in two parts - the overlapping
			//	part and the non-overlapping part, if any.
			apptRect = *r;

			//	Select side on which to overlap the bars:
			if (TimeToInt (lastEndTimeLeft) > TimeToInt (lastEndTimeRight))
				overlapOnLeft = false;
			else
				overlapOnLeft = true;

			//	The overlap area ends at the earlier of the appropriate
			//	lastEndTime or the appt's endTime.
			if (overlapOnLeft &&
				 (TimeToInt(appts[i].endTime) > TimeToInt (lastEndTimeLeft)))
				WeekViewGetEventBounds (appts[i].startTime, lastEndTimeLeft,
												startHour, endHour, &apptRect,
												hourHeight);
			else if (!overlapOnLeft &&
						(TimeToInt(appts[i].endTime) > TimeToInt (lastEndTimeRight)))
				WeekViewGetEventBounds (appts[i].startTime, lastEndTimeRight,
												startHour, endHour, &apptRect,
												hourHeight);
			else
				WeekViewGetEventBounds (appts[i].startTime, appts[i].endTime,
												startHour, endHour, &apptRect,
												hourHeight);

			//	Select side to overlap
			if (!overlapOnLeft)
				AdjustEventRight (&apptRect);
			else
				AdjustEventLeft (&apptRect);

			WinSetPattern(&overLapAppt);
			WinFillRectangle(&apptRect, 0);
			WinDrawRectangleFrame(simpleFrame, &apptRect);
			WinSetPattern(&regAppt);
			
			//	Now do the non-overlapping part.
			if ((overlapOnLeft &&
				  TimeToInt(appts[i].endTime) <= TimeToInt (lastEndTimeLeft)) ||
				 (!overlapOnLeft &&
				  TimeToInt(appts[i].endTime) <= TimeToInt (lastEndTimeRight)))
				continue;			//	No non-overlapping part
			apptRect = *r;
			if (overlapOnLeft)
				{
				WeekViewGetEventBounds (lastEndTimeLeft, appts[i].endTime,
												startHour, endHour, &apptRect,
												hourHeight);
				AdjustEventLeft (&apptRect);
				UpdateEndTime (&(appts[i].endTime), &lastEndTimeLeft, endHour);
				}
			else
				{
				WeekViewGetEventBounds (lastEndTimeRight, appts[i].endTime,
												startHour, endHour, &apptRect,
												hourHeight);
				AdjustEventRight (&apptRect);
				UpdateEndTime (&(appts[i].endTime), &lastEndTimeRight, endHour);
				}

			WinFillRectangle(&apptRect, 0);
			WinDrawRectangleFrame(simpleFrame, &apptRect);
			
			}	//	end of if <overlapping appt>

		//	Check for overlap with left side only:
		else if ((appts[i].startTime.hours < lastEndTimeLeft.hours) ||
					((appts[i].startTime.hours == lastEndTimeLeft.hours) &&
					 (appts[i].startTime.minutes < lastEndTimeLeft.minutes)))
			{	//	draw non-overlapping appt on right side; update right end time
			apptRect = *r;							//	Use pre-calculated x & y coords.
			WeekViewGetEventBounds (appts[i].startTime, appts[i].endTime,
											startHour, endHour, &apptRect,
											hourHeight);
			AdjustEventRight (&apptRect);

			WinFillRectangle(&apptRect, 0);
			WinDrawRectangleFrame(simpleFrame, &apptRect);
			UpdateEndTime (&(appts[i].endTime), &lastEndTimeRight, endHour);
			}
			   
		//	Check for overlap with right side only:
		else if ((appts[i].startTime.hours < lastEndTimeRight.hours) ||
					((appts[i].startTime.hours == lastEndTimeRight.hours) &&
					 (appts[i].startTime.minutes < lastEndTimeRight.minutes)))
			{	//	draw non-overlapping appt on left side; update left end time
			apptRect = *r;							//	Use pre-calculated x & y coords.
			WeekViewGetEventBounds (appts[i].startTime, appts[i].endTime,
											startHour, endHour, &apptRect,
											hourHeight);
			AdjustEventLeft (&apptRect);

			WinFillRectangle(&apptRect, 0);
			WinDrawRectangleFrame(simpleFrame, &apptRect);
			UpdateEndTime (&(appts[i].endTime), &lastEndTimeLeft, endHour);
			}

		//	Appt does not overlap previous appt - check for overlap with
		//	next appt.
		else if (((i + 1) < numAppts) &&
					((appts[i+1].startTime.hours < appts[i].endTime.hours) ||
					 ((appts[i+1].startTime.hours == appts[i].endTime.hours) &&
					  (appts[i+1].startTime.minutes < appts[i].endTime.minutes))))
			{	//	draw non-overlapping appt on left side; update left end time.
			apptRect = *r;							//	Use pre-calculated x & y coords.
			WeekViewGetEventBounds (appts[i].startTime, appts[i].endTime,
											startHour, endHour, &apptRect,
											hourHeight);
			AdjustEventLeft (&apptRect);

			WinFillRectangle(&apptRect, 0);
			WinDrawRectangleFrame(simpleFrame, &apptRect);
			UpdateEndTime (&(appts[i].endTime), &lastEndTimeLeft, endHour);
			}	//	end of if <overlapping next appt>

		else	//	Appt does not overlap previous appts:
			{	//	Draw full width appt; update both left & right end times.
			apptRect = *r;							//	Use pre-calculated x & y coords.
			WeekViewGetEventBounds (appts[i].startTime, appts[i].endTime,
											startHour, endHour, &apptRect,
											hourHeight);

			WinFillRectangle(&apptRect, 0);
			WinDrawRectangleFrame(simpleFrame, &apptRect);
			UpdateEndTime (&(appts[i].endTime), &lastEndTimeLeft, endHour);
			UpdateEndTime (&(appts[i].endTime), &lastEndTimeRight, endHour);
			}	//	end of if <non-overlapping appt>

		}	//	end of for <each appt in day>
		

	//	Clean up after drawing events
	MemPtrUnlock(appts);
	WinSetPattern(&origPattern);
	
	}	//	end of WeekViewDayDrawAppts
		

/***********************************************************************
 *
 * FUNCTION:    WeekViewCreateEventBar
 *
 * DESCRIPTION:	This routine calculates the area of a given day's
 *						event bar.
 *
 * PARAMETERS:		RectanglePtr		day - full day's bounds
 *						RectanglePtr		r - points to rect to be filled with
 *													event bar's coords.  The resulting
 *													bar does not include the frame around
 *													it.  The top & bottom of the frame
 *													should be added before this is passed
 *													to GetEventBounds
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date			Description
 *			----	----			-----------
 *			kcr	8/10/95		Initial Revision
 *
 ***********************************************************************/
static void WeekViewCreateEventBar (RectanglePtr day, RectanglePtr r)
	{
 	//	NOTE: since this is a framed event bar, the bounds of the bar must
 	//	be shrunk 1 pix on top & sides to keep the frame (drawn outside of passed
 	//	rect) within the bounds.  This is only nesc because we are using 
 	//	a frame around the event bar.
 	r->topLeft.x = day->topLeft.x + weekViewDayHMargin + 1;
 	r->topLeft.y = day->topLeft.y +
 						weekViewDayDisplayHeight +
 						weekViewDateDisplayHeight + 1;
 	r->extent.x = day->extent.x - 2*weekViewDayHMargin - 1;
 	r->extent.y = day->extent.y -
 						weekViewDayDisplayHeight -
 						weekViewDateDisplayHeight - 1;
 	}	//	end of WeekViewCreateEventBar
 					

/***********************************************************************
 *
 * FUNCTION:    WeekViewDayDraw
 *
 * DESCRIPTION:	This routine draws a passed DayObject structure.
 *
 * PARAMETERS:		DayType				*day - the day to draw
 *						UInt16				startHour - first displayed hour of the
 *												day
 *						UInt16				endHour - end of event bar display
 *						UInt16				hourHeight - vertical size of hour-long
 *												event
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date			Description
 *			----	----			-----------
 *			kcr	7/31/95		Initial Revision
 *			kcr	10/3/95		remove frame around whole day.
 *			kcr	10/13/95		don't draw days which are outside of date range
 *
 ***********************************************************************/
static void WeekViewDayDraw (DayType *day, UInt16 startHour, UInt16 endHour,
									  UInt16 hourHeight)
 	{
 	RectangleType			r;

	//	Only draw days which are in range.
	if (day->date.day == outOfRangeDay)
		return;

 	//	Use day bounds to create event bar bounds
 	WeekViewCreateEventBar (&(day->bounds), &r);

 	//	Draw the appointments - including overlaps.  The current appointment
 	//	is highlighted specially.  Only show portions of events which fall
 	//	between startHour & endHour.
	if (day->numAppts != 0)
		{
		//	Pass event bar to the event drawing routine, including the top &
		//	bottom frame areas.
		r.topLeft.y--;
		r.extent.y += 2;
		WeekViewDayDrawAppts (day->apptsH, day->numAppts, &r, startHour,
									 endHour, hourHeight);
 		}
  	}	//	end of WeekViewDayDraw


/***********************************************************************
 *

⌨️ 快捷键说明

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