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

📄 dateagenda.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************
 *
 * Copyright (c) 1995-2003 PalmSource, Inc. All rights reserved.
 *
 * File: DateAgenda.c
 *
 * Release: Palm OS 5 SDK (68K) R3.
 *
 * Description:
 *	  Display and support code for Datebook's Agenda view.
 *
 *****************************************************************************/

#include <PalmOS.h>
#include <FntGlue.h>

#include <PalmUtils.h>

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

extern ECApptDBValidate (DmOpenRef dbP);


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

#define minDatebookRows					1
#define maxDatebookRows					6
#define scrollerInset					1

#define minToDoRows						0

#define adjustSeparatorTop				2
#define adjustCategoryTop				2
#define adjustCategoryBottom			0

// DOLATER ??? - Copied from ToDo.c. Remove when obviated by ToDoLib

#define toDoPrefsVersionNum			3
#define todoPrefID						0x00
#define toDoDBName						"ToDoDB"
#define toDoDBType						'DATA'

// Columns in the ToDo table of the list view.
#define completedColumn					0
#define priorityColumn					1
#define descColumn						2
#define dueDateColumn					3
#define categoryColumn					4

#define spaceBeforeDesc					2
#define spaceBeforeCategory			2

#define maxDateTemplateLen				31


// Field numbers, used to indicate where search string was found.
#define descSearchFieldNum				0
#define noteSearchFieldNum				1

#define noAppointments					0xffff
#define noTasks							0xffff

typedef struct {
	UInt16				currentCategory;
	FontID			v20NoteFont;		// For 2.0 compatibility (BGT)
	Boolean			showAllCategories;
	Boolean 			showCompletedItems;
	Boolean 			showOnlyDueItems;
	Boolean			showDueDates;
	Boolean			showPriorities;
	Boolean			showCategories;
	Boolean			saveBackup;
	Boolean			changeDueDate;

	// Version 3 preferences
	FontID			listFont;
	FontID			noteFont;		// For 3.0 and later units.	(BGT)

	UInt8				reserved;
} ToDoPreferenceType;


/***********************************************************************
 *
 *	Globals
 *
 ***********************************************************************/

static AgendaType					Agenda;
extern privateRecordViewEnum	PrivateRecordVisualStatus;
extern UInt16				PendingUpdate;					// code of pending day view update


/***********************************************************************
 *
 *	Internal Functions
 *
 ***********************************************************************/

void					AgendaViewInitDatebook (
								FormPtr							frm );
void					AgendaViewInitToDo (
								FormPtr							frm );
static void			AgendaViewChangeDate (
								FormType*						inFormP,
								DateType							inDate );
static void AgendaViewCountDisplayLines (
								FormType*						inFormP,
								UInt16							inApptCount,
								UInt16							inToDoCount,
								UInt16*							outApptLinesP,
								UInt16*							outToDoLinesP );
static void 		AgendaViewLayout (
								FormType*						inFormP,
								UInt16							inApptCount,
								UInt16							inToDoCount );
static void			AgendaViewLayoutTables (
								FormType*						inFormP,
								UInt16							inApptLineCount,
								UInt16							inToDoLineCount );
static void 		AgendaViewSetTopAppointment ();
static void			AgendaViewSetTopTask ();
static void			AgendaViewLayoutAppointments (
								FormType*						inFormP,
								RectangleType*					ioBoundsP,
								UInt16							inApptLineCount );
static void			AgendaViewLayoutSeparator (
								FormType*						inFormP,
								RectangleType*					ioBoundsP );
static UInt16		AgendaViewObjectSetTop (
								FormType*						inFormP,
								UInt16							inObjectID,
								UInt16							inTop );
static void			AgendaViewLayoutTasks (
								FormType*						inFormP,
								RectangleType*					ioBoundsP,
								UInt16							inToDoLineCount );
static void			AgendaViewUpdateScroller (
								FormType*						inFormP,
								UInt16							inObjectID,
								UInt16							inAssocObjectID,
								UInt16							inRecordCount,
								UInt16							inVisibleCount,
								UInt16							inLineHeight );
static void			AgendaViewEraseObject (
								FormType*						inFormP,
								UInt16							inObjectID );
static void			AgendaViewSetScrollThumb (
								FormType*						inFormP,
								UInt16							inObjectID,
								UInt16							inValue );
static void			AgendaViewRefreshLayoutTasks (
								FormType*						inFormP );
static void			AgendaViewFillTitle (
								FormPtr							frm );
static void			AgendaViewFillAppointmentsTitle (
								FormType*						frmP );
static void			AgendaViewFillAppointments (
								FormType*						inFormP );
static void			AgendaViewFillTasksTitle (
								FormType*						inFormP,
								RectangleType*					ioBoundsP );
static void			AgendaViewFillTasks (
								FormType*						inFormP );
static void			AgendaDayViewScroll (
								Int16								delta);
static void			AgendaViewGoToDate ( );

static void			AgendaViewDrawDate (
								FormType*						inFormP );
static void			AgendaViewDrawTime (
								FormType*						inFormP );
static void			AgendaViewDrawSeparator (
								FormType*						inFormP );
static void			AgendaDateToDOWDM (
								DateType							inDate,
								Char*								outAscii );

static Err			AgendaViewGetApptDesc (
								void*								table,
								Int16								row,
								Int16								column,
								Boolean							editable,
								MemHandle*						dataH,
								Int16*							dataOffset,
								Int16*							textAllocSize,
								FieldPtr							fld );

#ifdef FORM_GADGET_TYPE_IN_CALLBACK_DEFINED
	// Added for Compatibility with SDK 4.0 update 1
	static Boolean		AgendaDividerDraw (
									FormGadgetTypeInCallback*		inGadgetP,
									UInt16							inCommand,
									void*							inParamP );
#else
	static Boolean		AgendaDividerDraw (
									FormGadgetType*					inGadgetP,
									UInt16							inCommand,
									void*							inParamP );
#endif

static void			AgendaTitleDraw (
								void*								inTableP,
								Int16								inRow,
								Int16								inColumn,
								RectangleType*					inBoundsP );
static void			AgendaApptDrawTime (
								void*								inTableP,
								Int16								inRow,
								Int16								inColumn,
								RectangleType*					inBoundsP );
static void			AgendaApptDrawDesc (
								void*								inTableP,
								Int16								inRow,
								Int16								inColumn,
								RectangleType*					inBoundsP );


Boolean				AgendaViewHandleTblEnter (
								EventType*							event );

static MemHandle	AgendaLoadAppointments (
								DateType							inDate );
static void			AgendaFreeAppointments ( );
static MemHandle	AgendaGetAppointments ( );
static void			AgendaSetAppointments (
								const MemHandle				inAppointmentsH,
								UInt16							inAppointmentCount );
static UInt16		AgendaGetAppointmentCount ( );
static void			AgendaViewGetScrollableRect (
								FormType*						inFormP,
								RectangleType*					outBoundsP );
static UInt16		AgendaViewGetSeparatorHeight (
								FormType*						inFormP );
static UInt16		AgendaViewGetDatebookDefaultHeight (
								FormType*						inFormP );

static Boolean		SeekRecord (
								DmOpenRef						inDB,
								UInt16*							inIndexP,
								UInt16							inOffset,
								Int16								inDirection,
								UInt16							inCategory,
								DateType							inDate,
								Boolean							inShowCompleted,
								Boolean							inShowDueOnly );
static UInt16		CountRecords (
								DmOpenRef						inDB,
								UInt16*							outIndices,
								UInt16							inIndexCount,
								UInt16							inCategory,
								DateType							inDate,
								Boolean							inShowCompleted,
								Boolean							inShowDueOnly );
static void ListInitTableRow (TablePtr table, UInt16 row, UInt16 recordNum,
	Int16 rowHeight);

void					LaunchToDoWithRecord (
								DmOpenRef					inDB,
								UInt16						inRecordNum );
void					GoToAppointment (
								DmOpenRef					inDB,
								UInt16						inRecordNum );


/***********************************************************************
 *
 *	Temporary Stuff
 *
 ***********************************************************************/

// DOLATER ??? - Temporary hack. Move prefs code into new To Do library.
// DOLATER ??? - Use new API instead of globals to access these settings.
static FontID		NoteFont = stdFont;						// font used in note view
static UInt16		CurrentCategory = dmAllCategories;	// currently displayed category
static char			CategoryName [dmCategoryLength];		// name of the current category
static Boolean		ShowAllCategories = true;				// true if all categories are being displayed
static Boolean 	ShowCompletedItems = true;				// true if completed items are being displayed
static Boolean 	ShowOnlyDueItems = false;				// true if only due items are displayed
static Boolean		ShowDueDates = false;					// true if due dates are displayed in the list view
static Boolean		ShowPriorities = true;					// true if priorities are displayed in the list view
static Boolean		ShowCategories = false;					// true if categories are displayed in the list view
static Boolean		SaveBackup = true;						// true if save backup to PC is the default
static Boolean		ChangeDueDate = false;					// true if due date is changed to completion date when completed
static FontID		ListFont = stdFont;						// font used to draw to do item
static UInt16		TopVisibleRecord = 0;
// Number of system ticks (1/60 seconds) to display crossed out item
// before they're erased.
#define crossOutDelay					40


static UInt16 ListViewGetColumnWidth (UInt16 column);
static Err ListViewGetDescription (void* table, UInt16 row, UInt16 column,
	Boolean editable, MemHandle* textH, UInt16* textOffset, UInt16* textAllocSize,
	FieldPtr fld);
static Boolean ListViewSaveDescription (void* table, UInt16 row, UInt16 column);
static void ListViewDrawDueDate (void* table, Int16 row, Int16 column,
	RectanglePtr bounds);
static void ListViewDrawCategory (void* table, Int16 row, Int16 column,
	RectanglePtr bounds);
static void			ListViewDrawDesc (
								void*								inTableP,
								Int16								inRow,
								Int16								inColumn,
								RectangleType*					inBoundsP );
static void * GetObjectPtr (UInt16 objectID);
static UInt16 ListViewSelectCategory (void);
static void ListViewDrawTable (UInt16 updateCode);
static void ListViewScroll (Int16 delta);
static void ChangeCategory (UInt16 category);

Err	ToDoAppInfoInit(DmOpenRef dbP);

static UInt16 CountMemoryChunks(UInt16 ownerID);
static void WatchMemoryChunkCount(void);

Char* GetToDoNotePtr (ToDoDBRecordPtr recordP);
static void ListViewCrossOutItem (Int16 row);
static void ListViewChangeCompleteStatus (Int16 row, UInt16 complete);

extern void ECToDoDBValidate(DmOpenRef dbP);

extern void GoToItem (GoToParamsPtr goToParams, Boolean launchingApp);

static void			CheckDBLeaks (
								DmOpenRef						inDB );
static void ToDoLoadPrefs ();


// Checking for leaks takes a long time with large databases,
// so turn it off, by default. At some point, there may be a better
// mechanism for toggling settings like this from the build environment,
// but, for now, just unlock the file and comment out the unwanted setting.
// (Note: This used to be keyed of off ERROR_CHECK_LEVEL, but this is still
// set to ERROR_CHECK_FULL during alpha testing.)

//#define CHECK_DB_LEAKS(db)		CheckDBLeaks (db)
#define CHECK_DB_LEAKS(db)


/***********************************************************************
 *
 * FUNCTION:    AgendaViewInit
 *
 * DESCRIPTION: Initialize the Agenda view of the Datebook application.
 *
 * PARAMETERS:  frm - pointer to the day view form.
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			rbb	5/28/99	Initial Revision
 *			CS		11/14/00	Use PrefGetPreference instead of PrefGetPreferences.
 *	2002-10-21	CS		If we've got support for the lunar calendar, then
 *							display the lunar view push button (otherwise spread
 *							buttons out a bit).
 *
 ***********************************************************************/
void
AgendaViewInit (
	FormPtr							frm )
{
	UInt16 mode;
	FontID curFont;

#if EMULATION_LEVEL != EMULATION_NONE
	ECApptDBValidate (ApptDB);
#endif

	ToDoLoadPrefs();

	Agenda.apptDB = ApptDB;
	Agenda.apptTopVisibleIndex = 0;
	Agenda.apptFont = ApptDescFont;
	Agenda.apptLineCount = 0;

	curFont = FntSetFont (Agenda.apptFont);
	Agenda.apptLineHeight = FntLineHeight ();
	FntSetFont (curFont);

	mode = (PrivateRecordVisualStatus == hidePrivateRecords) ?
					dmModeReadOnly : (dmModeReadOnly | dmModeShowSecret);

	ToDoGetDatabase (&Agenda.todoDB, mode);	// DOLATER ??? - What should be done on failure?
	Agenda.todoLineCount = 0;

#ifdef USE_NATIVE_TODO_FONT
	Agenda.todoFont = ListFont;
	curFont = FntSetFont (Agenda.todoFont);
	Agenda.todoLineHeight = FntLineHeight ();
	FntSetFont (curFont);
#else
	Agenda.todoFont = Agenda.apptFont;	// same as appointments
	Agenda.todoLineHeight = Agenda.apptLineHeight;
#endif

	Agenda.timeFont = boldFont;
	Agenda.timeFormat = (TimeFormatType)PrefGetPreference(prefTimeFormat);

//	Agenda.date = Date;
	Agenda.dateFont = boldFont;
	Agenda.dateFormat =		(DateFormatType) PrefGetPreference (prefDateFormat);
	Agenda.longDateFormat =	(DateFormatType) PrefGetPreference (prefLongDateFormat);

	AgendaViewInitDatebook (frm);
	AgendaViewInitToDo (frm);

	FrmSetGadgetHandler (frm, FrmGetObjectIndex (frm, AgendaDivider), AgendaDividerDraw);

	// Display the Lunar View push button if we've got support for it.
	if (DateSupportsLunarCalendar()) {
		FrmShowObject (frm, FrmGetObjectIndex(frm, AgendaLunarViewButton));
		
	// Otherwise, spread the buttons out a bit to make use of extra space.
	} else {
		RectangleType lastButtonBounds;
		RectangleType buttonBounds;
		
		FrmGetObjectBounds(	frm,
									FrmGetObjectIndex(frm, AgendaMonthViewButton),
									&lastButtonBounds);
		FrmGetObjectBounds(	frm,
									FrmGetObjectIndex(frm, AgendaAgendaViewButton),
									&buttonBounds);
		buttonBounds.topLeft.x =	(	lastButtonBounds.topLeft.x
											+	lastButtonBounds.extent.x
											+	1);
		FrmSetObjectBounds(	frm,
									FrmGetObjectIndex(frm, AgendaAgendaViewButton),
									&buttonBounds);
									
		lastButtonBounds = buttonBounds;

⌨️ 快捷键说明

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