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

📄 datemonth.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
📖 第 1 页 / 共 4 页
字号:
 *			jmp	10/6/99	Replace FrmGetActiveForm() with FrmGetFormPtr();
 *
 ***********************************************************************/
static MonthPtr MonthViewGetMonthPtr (void)
	{
	FormPtr frm;
	
	frm = FrmGetFormPtr (MonthView);
	return (FrmGetGadgetData (frm, FrmGetObjectIndex (frm, MonthGadget)));
	}


/***********************************************************************
 *
 * FUNCTION:    MonthViewSetTitle
 *
 * DESCRIPTION: This routine set the title of the Month View
 *
 * PARAMETERS:  monthP  - pointer to month object (MonthType)
 *
 * RETURNED:	 nothing
 *
 * HISTORY:
 *		04/10/96	art	Created by Art Lamb.
 *		09/08/99	kwk	Use DateTemplateToAscii & load format from string resource.
 *		10/6/99	jmp	Replace FrmGetActiveForm() with FrmGetFormPtr();
 *	2002-10-23	CS		Set title to text describing lunar month for Lunar
 *							View.
 *
 ***********************************************************************/
static void MonthViewSetTitle (MonthPtr monthP)
	{
	Char				title [longDateStrLength];
	MemHandle		templateH;
	Char*				templateP;
	DateTimeType	dateTime;
	UInt32			dateSeconds;
	UInt16			lastDay;
	UInt16			lunarYear;
	UInt16			lunarMonth;
	UInt16			lunarDay;
	Boolean			isLeapMonth;
	Err				tErr = errNone;

	if (pMonthViewButtonID == MonthLunarViewButton)
		{
		dateTime.second = 0;
		dateTime.minute = 0;
		dateTime.hour = 0;
		dateTime.month = monthP->month;
		dateTime.year = monthP->year;
		
		/* Find the date on which the first lunar month within this Gregorian month
		begins.  If no such date exists, then just use the lunar month of the last
		day in this Gregorian month (same as the lunar month for the rest of the
		days in this Gregorian month).
		*/
		lastDay = DaysInMonth(monthP->month, monthP->year);
		for (dateTime.day = 1; dateTime.day < lastDay; dateTime.day++)
			{
			dateSeconds = TimDateTimeToSeconds(&dateTime);
			tErr = DateSecondsToLunarDate(dateSeconds,
													&lunarYear,
													&lunarMonth,
													&lunarDay,
													&isLeapMonth);
			if (tErr != errNone)
				{
				ErrNonFatalDisplay("Error converting seconds to lunar date");
				return;
				}
			if (lunarDay == timFirstChineseLunarDay)
				{
				break;
				}
			}
		tErr = DateToLunarStr(	lunarYear,
										lunarMonth,
										timOmitLunarDay,
										isLeapMonth,
										title,
										sizeof(title)-1);
		if (tErr != errNone)
			{
			ErrNonFatalDisplay("Error formatting lunar date string");
			return;
			}
		}
	else
		{
	templateH = DmGetResource(strRsc, MonthViewTitleStrID);
	templateP = (Char*)MemHandleLock(templateH);
	DateTemplateToAscii(templateP, monthP->month, 1, monthP->year, title, sizeof(title) - 1);
	MemHandleUnlock(templateH);
		}
	FrmCopyTitle (FrmGetFormPtr (MonthView), title);
	TimeDisplayed = false;
	}

	
/***********************************************************************
 *
 * FUNCTION:    MonthViewHideTime
 *
 * DESCRIPTION: If the title of the Day View is displaying the current 
 *              time, this routine will change the title to the standard
 *					 title (the current date).
 *
 * PARAMETERS:  nothing
 *
 * PARAMETERS:  hide - true to always hide, false hide only if
 *                     to time has been display for the require
 *                      length of time.
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	5/14/96	Initial Revision
 *			grant	2/2/99	Use TimeToWait(), don't use EvtSetNullEventTick()
 *
 ***********************************************************************/
static void MonthViewHideTime (Boolean hide)
{
	MonthPtr 	monthP;
	if (TimeDisplayed)
		{
		if (hide || TimeToWait() == 0)
			{
			monthP = MonthViewGetMonthPtr ();
			MonthViewSetTitle (monthP);
			}
		}
}


/***********************************************************************
 *
 * FUNCTION:    MonthSelectDayRect
 *
 * DESCRIPTION: This routine selects or unselects day in the month
 *					 object.
 *
 * PARAMETERS:	 monthP   - pointer to control object (ControlType)
 *              r        - pointer to day's rectangle
 *					 selected - says whether to draw the rectangle selected
 *									or unselected
 *
 * RETURNED:	nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			jmp	10/31/99	Initial Revision.
 *			jmp	11/06/99	Oops, was just doing a WinResetClip() instead of
 *								save/restore WinSetClip().
 *			jmp	11/14/99	Added support for drawing the current day's selection
 *								unselected to get the right selection effect on
 *								"today."
 *			jmp	11/19/99	Use WinScreenLock()/WinScreenUnlock() to eliminate all of
 *								the ugly redrawing effects.
 *       jmp   12/02/99 Fix bug #24377.  Don't call WinScreenUnlock() if WinScreenLock()
 *                      fails.
 *                          
 ***********************************************************************/
static void MonthSelectDayRect (MonthPtr monthP, RectangleType *r, Boolean selected)
{
	RectangleType savedClip;
	UInt8 * lockedWinP;
	
	// Draw everything offscreen to begin with -- we have a lot to redraw, and
	// it's somewhat unsightly to see it all happen onscreen.  But still restrict
	// the clipping rectangle to get the effect we want.
	//
	lockedWinP = WinScreenLock(winLockCopy);
	WinGetClip(&savedClip);
	WinSetClip(r);
	
	// Always redraw unselected first.
	//
	DrawMonth(monthP, !selected);
	
	// If selection is desired, do that now.
	//
	if (selected)
	{
		RectangleType todayRect;
		DateTimeType today;

		// First, draw the entire rectangle selected.
		//
		MonthDrawInversionEffect(r, 0);
		
		// If we're drawing "today," then draw the
		// day selection itself unselected.
		//
		TimSecondsToDateTime(TimGetSeconds(), &today);
		GetDaySelectionBounds(monthP, today.day, &todayRect);
		
		if (TodayIsVisible(monthP, today) && RctPtInRectangle(r->topLeft.x, r->topLeft.y, &todayRect))
		{
			WinSetClip(&todayRect);
			DrawMonth(monthP, dontDrawDaySelected);
		}
	}

	// Now that we're done drawing, reset the clipping rectangle, and put everything we've done back
	// onscreen.
	//
	WinSetClip(&savedClip);
	if (lockedWinP)
		WinScreenUnlock();
}


/***********************************************************************
 *
 * FUNCTION:    MonthSelectDay
 *
 * DESCRIPTION: This routine selects a day in the month object.
 *
 * PARAMETERS:	 monthP  - pointer to control object (ControlType)
 *              eventP  - pointer to an EventType structure.
 *              dateP   - returned: pointer to the date selected
 *
 * RETURNED:	true if the event was handle or false if it was not.
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	4/9/96	Initial Revision
 *			jmp	10/31/99	Eliminate WinInvertRectangle() by calling
 *								MonthSelectDayRect() instead.
 *
 ***********************************************************************/
static Boolean MonthSelectDay (MonthPtr monthP, EventType* eventP, DatePtr dateP)
	{
	Int16				x, y;
	Int16       	item;
	Int16       	daysInMonth;
	Int16       	firstDayInMonth;
	Int16				cellWidth, cellHeight;
	Boolean			penDown;
	Boolean			selected;
	RectangleType	r;
	
	firstDayInMonth = FirstDayOfMonth (monthP);
	daysInMonth = DaysInMonth (monthP->month, monthP->year);

	// Restrict the selection bounds.  The top should be moved down
	// to exclude selecting the day of week titles.  The bottom should
	// be moved up to the last week with a day in it.
	RctCopyRectangle (&(monthP->bounds), &r);
	r.topLeft.y += r.extent.y / linesInMonthPlusTitle;
	r.extent.y = (r.extent.y / linesInMonthPlusTitle) *
		(((firstDayInMonth + daysInMonth - 1) / 7) + 1);

	if (! RctPtInRectangle (eventP->screenX, eventP->screenY, &r))
		return false;

	// Compute the bounds of the day the pen is on.
	item = MapPointToItem (eventP->screenX, eventP->screenY, &monthP->bounds);

	cellWidth = monthP->bounds.extent.x / daysInWeek;
	cellHeight = monthP->bounds.extent.y / linesInMonthPlusTitle;
	r.topLeft.x = monthP->bounds.topLeft.x + (item % daysInWeek) * cellWidth + 1;
	r.topLeft.y = monthP->bounds.topLeft.y + ((item / daysInWeek) + 1) * cellHeight + 1;
	r.extent.x = cellWidth - 1;
	r.extent.y = cellHeight - 1;

	// Draw the selected day.
	selected	= true;
	MonthSelectDayRect (monthP, &r, selected);

	// Track the pen until it's released, highlight or unhighlight the
	// item as the pen move in and out of it.
	do 
		{
		PenGetPoint (&x, &y, &penDown);

		if (RctPtInRectangle (x, y, &r))
			{
			if (!selected)
				{
				selected = true;
				MonthSelectDayRect (monthP, &r, selected);
				}
			}

		else if (selected)
			{
			selected = false;
			MonthSelectDayRect (monthP, &r, selected);
			}

		} while (penDown);


	// Exit if the pen was released outside the item.
	if (!selected)
		return (false);

	selected = false;
	MonthSelectDayRect (monthP, &r, selected);

	dateP->month = monthP->month;
	dateP->year = monthP->year - firstYear;

	// Is the selection is outside of the month?
	if ((unsigned) (item - firstDayInMonth) >= (unsigned) daysInMonth)
		{
		// Move to the month before or after the current month.
		dateP->day = 1;
		DateAdjust (dateP, (item - firstDayInMonth));
		}
	else
		{
		dateP->day = item - firstDayInMonth + 1;
		}

	return true;
	}



/***********************************************************************
 *
 * FUNCTION:    MonthViewShowTime
 *
 * DESCRIPTION: This routine display the current time in the title of the
 *              month view.
 *
 * PARAMETERS:  frm - pointer to the day view form.
 *
 * RETURNED:    nothing
 *
 * NOTE:        The global variable TimeDisplayed is set to true by this
 *              routine.
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	7/15/96	Initial Revision
 *			jmp	10/6/99	Replace FrmGetActiveForm() with FrmGetFormPtr();
 *
 ***********************************************************************/
static void MonthViewShowTime (void)
{
	Char				title[timeStringLength];
	DateTimeType 	dateTime;

	TimSecondsToDateTime (TimGetSeconds (), &dateTime);
	TimeToAscii (dateTime.hour, dateTime.minute, TimeFormat, title);
	FrmCopyTitle (FrmGetFormPtr (MonthView), title);
	
	TimeDisplayed = true;
	TimeDisplayTick = TimGetTicks () + timeDisplayTicks;
}


/***********************************************************************
 *
 * FUNCTION:		MonthViewGotoDate
 *
 * DESCRIPTION:	This routine displays the date picker so that the 
 *						user can select a month to navigate to.  If the date
 *						picker is confirmed, the month selected month is 
 *                confirmed
 *
 *						This routine is called when a "go to" button is pressed.
 *              
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	5/20/96	Initial Revision
 *			jmp	10/31/99 Move WinEraseRectangle() & DrawAppointmentsInMonth()
 *								into DrawMonth() itself.
 *
 ***********************************************************************/
static void MonthViewGotoDate (void)
	{
	Char *		title;
	MemHandle	titleH;
	MonthPtr 	monthP;
	Int16 		day;

	// Get the title for the date picker dialog box.
	titleH = DmGetResource (strRsc, goToDateTitleStrID);
	title = MemHandleLock (titleH);

	monthP = MonthViewGetMonthPtr ();

	// Display the date picker.
	day = 1;
	if (SelectDay (selectDayByMonth, &monthP->month, &day, &monthP->year, title))
		{
		MonthViewSetTitle (monthP);
		DrawMonth (monthP, drawDaySelected);
		}

	MemHandleUnlock (titleH);
	}



/***********************************************************************
 *
 * FUNCTION:    MonthViewScroll
 *
 * DESCRIPTION: This routine scrolls the month view foreward or backwards
 *              by a month.
 *
 * PARAMETERS:  monthP  - pointer to month object (MonthType)
 *              direction - winUp (backwards) or winDown (foreward)
 *
 * RETURNED:	 nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	4/8/96	Initial Revision
 *			jmp	10/31/99 Move WinEraseRectangle() & DrawAppointmentsInMonth()
 *								into DrawMonth() itself.
 *
 ***********************************************************************/
static void MonthViewScroll (MonthPtr monthP, WinDirectionType direction)
{
	// Move backward one month.
	if (direction == winUp)
		{
		if (monthP->month > january)
			monthP->month--;

⌨️ 快捷键说明

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