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

📄 dateagenda.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
📖 第 1 页 / 共 5 页
字号:
		FrmGetObjectBounds(	frm,
									FrmGetObjectIndex(frm, AgendaGoToButton),
									&buttonBounds);
		buttonBounds.topLeft.x =	(	lastButtonBounds.topLeft.x
											+	lastButtonBounds.extent.x
											+	kButtonSpacing);
		FrmSetObjectBounds(	frm,
									FrmGetObjectIndex(frm, AgendaGoToButton),
									&buttonBounds);
	}

	// Load the appointments and tasks into the table object that will display them.
	// DOLATER ??? - Not yet sure what details govern this stuff
	if (PendingUpdate && ItemSelected)
		{
		AgendaViewChangeDate (frm, Date);
		}
	else
		{
//		AgendaViewFillTable (frm);
		AgendaViewChangeDate (frm, Date);
		}

	// Highlight the Agenda View push button.
//	FrmSetControlGroupSelection (frm, AgendaViewGroup, AgendaAgendaViewButton);
}


/***********************************************************************
 *
 * FUNCTION:    AgendaViewInitDatebook
 *
 * DESCRIPTION: Initialize the Datebook portion of the Agenda view.
 *
 * PARAMETERS:  frm - pointer to the agenda view form.
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			rbb	5/28/99	Initial Revision
 *
 ***********************************************************************/
void
AgendaViewInitDatebook (
	FormPtr							frm )
{
	UInt16 row;
	UInt16 rowsInTable;
	TablePtr table;

	// Initialize the table used to display the day's agenda.
	table = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, AgendaDatebookTable));

	rowsInTable = TblGetNumberOfRows (table);
	for (row = 0; row < rowsInTable; row++)
		{
		TblSetItemStyle (table, row, agendaApptTimeColumn, customTableItem);
		TblSetItemStyle (table, row, agendaApptDescColumn, customTableItem);
		}

	TblSetColumnUsable (table, agendaApptTimeColumn, true);
	TblSetColumnUsable (table, agendaApptDescColumn, true);
	TblSetColumnMasked (table, agendaApptDescColumn, true);

	TblSetColumnSpacing (table, agendaApptTimeColumn, agendaApptTimeColumnSpacing);

	// Set the callback routine that will load the description field.
	// (No callback for saving, since this is a read-only view.)
	TblSetLoadDataProcedure (table, agendaApptDescColumn, AgendaViewGetApptDesc);

	// Set the callback routine that draws the time field.
	TblSetCustomDrawProcedure (table, agendaApptTimeColumn, AgendaApptDrawTime);
	TblSetCustomDrawProcedure (table, agendaApptDescColumn, AgendaApptDrawDesc);
}


/***********************************************************************
 *
 * FUNCTION:    AgendaViewGetApptDesc
 *
 * DESCRIPTION: This routine returns a pointer to the description field
 *              of a appointment record.  This routine is called by
 *              the table object as a callback routine when it wants to
 *              display or edit the appointment's description.
 *
 * PARAMETERS:  inTable			- pointer to the Day View table (TablePtr)
 *              inRow			- row in the table
 *              inColumn		- column in the table
 *              inEditable		- true if the field will be edited by the table
 *					 outHandleP		- handle to the appointment record
 *              outOffsetP		- offset within the record of the desc field (returned)
 *              outSizeP		- allocated size the the description field (returned)
 *					 ioFieldP		- Table Mgr's field description
 *
 * RETURNED:    handle of the appointment record
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			rbb	6/4/99	Initial Revision
 *
 ***********************************************************************/
static Err AgendaViewGetApptDesc (
	void*								inTableP,
	Int16								inRow,
	Int16								inColumn,
	Boolean							inEditable,
	MemHandle*						outHandleP,
	Int16*							outOffsetP,
	Int16*							outSizeP,
	FieldType*						ioFieldP )
{
#pragma unused (inColumn, inEditable)

	Err								err = errNone;
	UInt16							apptIndex;
	ApptInfoPtr						appts;
	UInt16							recordNum;
	MemHandle						recordH;
	ApptDBRecordType				apptRec;
	FieldAttrType					attributes;

	Assert (inColumn == agendaApptDescColumn );
	Assert (outHandleP);
	Assert (outOffsetP);
	Assert (outSizeP);
	Assert (ioFieldP);

	*outHandleP = 0;

	// Override the default field attributes
	FldGetAttributes (ioFieldP, &attributes);
	attributes.underlined = false;
	attributes.editable = false;
	FldSetAttributes (ioFieldP, &attributes);

	// Get the appointment that corresponds to the table item.
	// The index of the appointment in the appointment list is stored
	// as the row id.
	apptIndex = TblGetRowID (inTableP, inRow);

	// If there aren't any appointments, show a message to that effect
	if (apptIndex == noAppointments)
		{
		*outHandleP = DmGetResource (strRsc, agendaNoAppointmentsStrID);
		*outOffsetP = 0;
		*outSizeP = MemHandleSize (*outHandleP);
		goto Exit;
		}

	// Get the record index of the next appointment
	appts = MemHandleLock (AgendaGetAppointments ());
	recordNum = appts[apptIndex].recordNum;
	MemPtrUnlock (appts);

	// Get the offset and length of the description field
	err = ApptGetRecord (Agenda.apptDB, recordNum, &apptRec, &recordH);

	if ( err == errNone )
		{
		*outHandleP = recordH;

		if ( apptRec.description != NULL )
			{
			*outOffsetP = (UInt16) ((UInt32) apptRec.description - (UInt32) apptRec.when);
			*outSizeP = StrLen (apptRec.description) + 1;  // one for null terminator
			}
		else
			{
			*outOffsetP = 0;
			*outSizeP = 0;
			}
		}

	MemHandleUnlock (recordH);

Exit:
	return (err);
}


/***********************************************************************
 *
 * FUNCTION:    AgendaViewChangeDate
 *
 * DESCRIPTION: This routine displays the date passed.
 *
 * PARAMETERS:  date - date to display
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	6/29/95	Initial Revision
 *
 ***********************************************************************/
static void AgendaViewChangeDate (
	FormType*						inFormP,
	DateType							inDate )
{
	CHECK_DB_LEAKS (Agenda.todoDB);

	// Keep the new date for future reference
	Date = inDate;
	Agenda.timeSeconds = TimGetSeconds ();

	// Find out how many appointments and tasks to display
	AgendaLoadAppointments (inDate);		// sets Agenda.apptCount

	// Tally up the number of displayable tasks and store the index
	// of the first in TopVisibleRecord
	Agenda.todoCount = CountRecords (Agenda.todoDB, &TopVisibleRecord, 1, CurrentCategory,
										Date, ShowCompletedItems, ShowOnlyDueItems);

	AgendaViewDrawDate (inFormP);
	AgendaViewDrawTime (inFormP);

	// Get all the appointments and empty time slots on the new day.
	AgendaViewEraseObject (inFormP, AgendaDatebookTable);
	AgendaViewEraseObject (inFormP, AgendaToDoTable);
	AgendaViewLayout (inFormP, Agenda.apptCount, Agenda.todoCount);

	// Determine the top items to display
	AgendaViewSetTopAppointment ();
//	AgendaViewSetTopTask ();

	// Fill the display tables
	AgendaViewFillAppointments (inFormP);
	AgendaViewFillTasks (inFormP);

	// Update the scroll arrows
	AgendaViewSetScrollThumb (inFormP, AgendaDatebookScroller, Agenda.apptTopVisibleIndex);
	AgendaViewSetScrollThumb (inFormP, AgendaToDoScroller, 0);

	// Draw the new day's events
	FrmSetControlGroupSelection (inFormP, AgendaViewGroup, AgendaAgendaViewButton);
	FrmDrawForm (inFormP);

	CHECK_DB_LEAKS (Agenda.todoDB);
}


/***********************************************************************
 *
 * FUNCTION:    AgendaViewLayout
 *
 * DESCRIPTION: This routine displays the date passed.
 *
 * PARAMETERS:  date - date to display
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			rbb	9/13/99	Initial Revision
 *
 ***********************************************************************/
static void AgendaViewLayout (
	FormType*						inFormP,
	UInt16							inApptCount,
	UInt16							inToDoCount )
{
	UInt16							apptLineCount;
	UInt16							todoLineCount;

	AgendaViewCountDisplayLines (inFormP, inApptCount, inToDoCount,
											&apptLineCount, &todoLineCount);

	// DOLATER rbb - Enhance performance by processing events during screen refresh,
	// checking to see if the displayed date has changed and, if so, starting over.
	// This code should also use offscreen drawing so that the user will never have
	// to see a partial redraw.

	if (Agenda.apptLineCount != apptLineCount)
		{
//		AgendaViewEraseObject (inFormP, AgendaDatebookTable);
		AgendaViewEraseObject (inFormP, AgendaDatebookScroller);
		AgendaViewEraseObject (inFormP, AgendaDivider);
		AgendaViewEraseObject (inFormP, AgendaToDoCategoryTrigger);
		}

	if ( (Agenda.apptLineCount != apptLineCount) || (Agenda.todoLineCount != todoLineCount) )
		{
		// Erase To Do
//		AgendaViewEraseObject (inFormP, AgendaToDoTable);
		AgendaViewEraseObject (inFormP, AgendaToDoScroller);
		}

	AgendaViewLayoutTables (inFormP, apptLineCount, todoLineCount);

	AgendaViewUpdateScroller (inFormP, AgendaDatebookScroller,AgendaDatebookTable,
										inApptCount, apptLineCount, Agenda.apptLineHeight);

	AgendaViewUpdateScroller (inFormP, AgendaToDoScroller, AgendaToDoTable,
										inToDoCount, todoLineCount, Agenda.todoLineHeight);

	Agenda.apptLineCount = apptLineCount;
	Agenda.todoLineCount = todoLineCount;
}


static void AgendaViewCountDisplayLines (
	FormType*						inFormP,
	UInt16							inApptCount,
	UInt16							inToDoCount,
	UInt16*							outApptLinesP,
	UInt16*							outToDoLinesP )
{
	UInt16							apptCount;
	UInt16							todoCount;
	RectangleType					agendaBounds;
	UInt16							agendaHeight;
	UInt16							separatorHeight;
	UInt16							apptSectionHeight;
	UInt16							todoSectionHeight;
	UInt16							apptDefaultCount;
	UInt16							todoDefaultCount;
	UInt16							apptDisplayCount;
	UInt16							todoDisplayCount;
	UInt16							apptDisplayHeight;
	UInt16							todoDisplayHeight;
	UInt16							remainingDisplayHeight;
	UInt16							remainingDisplayCount;

	// Compensate for empty sections, which will show something like,
	// "No Appointments Today"
	apptCount = max (minDatebookRows, inApptCount);
	todoCount = max (minToDoRows, inToDoCount);

	// Get the default sizes for each of the view sections
	AgendaViewGetScrollableRect (inFormP, &agendaBounds);
	agendaHeight = agendaBounds.extent.y;
	separatorHeight = AgendaViewGetSeparatorHeight (inFormP);
	apptSectionHeight = AgendaViewGetDatebookDefaultHeight (inFormP);
	todoSectionHeight = agendaHeight - separatorHeight - apptSectionHeight;

	// Convert those sizes into line counts
	apptDefaultCount = apptSectionHeight / Agenda.apptLineHeight;
	todoDefaultCount = todoSectionHeight / Agenda.todoLineHeight;

	// Adjust the layout for optimum viewing
	if (apptCount <= apptDefaultCount)
		{
		// All appointments fit within the standard area
		apptDisplayCount = apptCount;
		apptDisplayHeight = apptDisplayCount * Agenda.apptLineHeight;

		if (todoCount <= todoDefaultCount)
			{
			// All tasks fit within the standard area
			todoDisplayCount = todoCount;
			todoDisplayHeight = todoDisplayCount * Agenda.todoLineHeight;
			}
		else
			{
			// Extra tasks can grow into the unused appointment area
			remainingDisplayHeight = agendaHeight - separatorHeight - apptDisplayHeight;
			remainingDisplayCount = remainingDisplayHeight / Agenda.todoLineHeight;
			todoDisplayCount = min (todoCount, remainingDisplayCount);
			todoDisplayHeight = todoDisplayCount * Agenda.todoLineHeight;
			}
		}
	else if (todoCount <= todoDefaultCount)
		{
		// All tasks fit within the standard area
		todoDisplayCount = todoCount;
		todoDisplayHeight = todoDisplayCount * Agenda.todoLineHeight;

		// Extra appointments can grow into the unused task area
		remainingDisplayHeight = agendaHeight - separatorHeight - todoDisplayHeight;
		remainingDisplayCount = remainingDisplayHeight / Agenda.apptLineHeight;
		apptDisplayCount = min (apptCount, remainingDisplayCount);
		apptDisplayHeight = apptDisplayCount * Agenda.apptLineHeight;
		}
	else
		{
		// Both the appointment and task sections are full, so use the default layout
		apptDisplayCount = apptDefaultCount;
		apptDisplayHeight = apptDisplayCount * Agenda.apptLineHeight;
		todoDisplayCount = todoDefaultCount;
		todoDisplayHeight = todoDisplayCount * Agenda.todoLineHeight;
		}

	*outApptLinesP = apptDisplayCount;
	*outToDoLinesP = todoDisplayCount;
}


/***********************************************************************
 *
 * FUNCTION:    AgendaViewSetTopAppointment
 *
 * DESCRIPTION: This routine determines the first appointment that should
 *              be visible on the current day.  For all dates other than
 *              today the fisrt time slot of the appointment list
 *              is the first visible appointment.  For today the time
 *              slot that stats before to the current time should be the top
 *              visible time slot.
 *
 * PARAMETERS:  nothing.
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	6/29/95	Initial Revision
 *
 ***********************************************************************/
static void AgendaViewSetTopAppointment ()
{
	UInt16 i;
	TimeType time;
	DateTimeType dateTime;
	MemHandle apptsH;
	ApptInfoPtr apptsP;

	Agenda.apptTopVisibleIndex = 0;

	TimSecondsToDateTime (TimGetSeconds (), &dateTime);

	// If the current date is not today, then the first appointment
	// is the first one visible.
	if ( (dateTime.year - firstYear != Date.year) ||
		  (dateTime.month != Date.month) ||
		  (dateTime.day != Date.day))
		{
		return;
		}

	// If the current date is today, then the top visible appointment is
	// the appointment with the greatest end time that is before the
	// current time.
	time.hours = dateTime.hour;
	time.minutes = dateTime.minute;

	apptsH = AgendaGetAppointments ();

⌨️ 快捷键说明

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