/******************************************************************************
 *
 * Copyright (c) 1995-2000 Palm, Inc. or its subsidiaries.
 * All rights reserved.
 *
 * File: ToDoDB.h
 *
 * Release: Palm OS SDK 4.0 (63220)
 *
 * Description:
 *		Header for the To Do Manager
 *
 * History:
 *   	1/19/95  rsf - Created
 *		10/4/99	jmp - Added 
 *
 *****************************************************************************/

#ifndef __TDTODOMGR_H__
#define __TDTODOMGR_H__

#include <DateTime.h>

#define LocalizedAppInfoStr	1000

#define todoLabelLength			12
#define todoNumFields			16

#define toDoMaxPriority			5

// Dirty flags for to do application info
#define toDoSortByPriorityDirty	0x0001

// Sort orders
#define soDueDatePriority		0
#define soPriorityDueDate		1
#define soCategoryPriority		2
#define soCategoryDueDate		3


typedef struct {
    UInt16			renamedCategories;	// bitfield of categories with a different name
	char 				categoryLabels[dmRecNumCategories][dmCategoryLength];
	UInt8 			categoryUniqIDs[dmRecNumCategories];
	UInt8				lastUniqID;	// Uniq IDs generated by the device are between
										// 0 - 127.  Those from the PC are 128 - 255.
	UInt8				reserved1;	// from the compiler word aligning things
	UInt16			reserved2;
	UInt16			dirtyAppInfo;
	UInt8				sortOrder;
	UInt8				reserved3;
} ToDoAppInfoType;

typedef ToDoAppInfoType * ToDoAppInfoPtr;

// ToDoDBRecord.
//
// All strings are null terminated and appear within the record.
//
typedef struct {
	DateType dueDate;
	UInt8 priority;		// high bit is complete flag
	char description;
} ToDoDBRecord;

typedef ToDoDBRecord				ToDoDBRecordType;
typedef ToDoDBRecord*			ToDoDBRecordPtr;

// sizeDBRecord is the minimum size for the ToDoDBRecord structure.
// It assumes empty 'description' and 'note' fields.
// sizeDBRecord allocates an extra byte for the null character
// for the note string.
#define sizeDBRecord (sizeof (ToDoDBRecord) + 1)

// ToDoItemType
//
// This is the format of a to do record used by the application.  All 
// pointers are either NULL or point to data within the PackedDB record.
// All strings are null character terminated.
//
typedef struct {
	DateType 			dueDate;
	UInt8 				priority;		// high bit is complete flag
	UInt8					reserved;
	Char *				description;
	Char *				note;
} ToDoItemType;

typedef ToDoItemType * ToDoItemPtr;


#define completeFlag 	0x80
#define priorityOnly 	~completeFlag
#define toDoNoDueDate	0xffff


// Used for ToDoChangeRecord.
typedef enum  { 
	toDoPriority,
	toDoComplete,
	toDoDueDate,
	toDoDescription,
	toDoNote,
	toDoCategory } ToDoRecordFieldType;



#ifdef __cplusplus
extern "C" {
#endif


//-------------------------------------------------------------------
// Routines
//-------------------------------------------------------------------
Err ToDoNewRecord(DmOpenRef dbP, ToDoItemPtr item, UInt16 category, UInt16 *index);

Err ToDoInsertNewRecord (DmOpenRef dbP, UInt16 * index);

Err ToDoChangeRecord(DmOpenRef dbP, UInt16 * index, 
	ToDoRecordFieldType changedField, const void * data);

Err ToDoChangeSortOrder(DmOpenRef dbP, UInt8 sortOrder);

Err ToDoAppInfoInit(DmOpenRef dbP);

MemHandle ToDoGetAppInfo  (DmOpenRef dbP);

UInt8 ToDoGetSortOrder (DmOpenRef dbP);

void ToDoSort (DmOpenRef dbP);

Err ToDoGetDatabase (DmOpenRef *dbPP, UInt16 mode);

void ToDoSetDBBackupBit (DmOpenRef dbP);


#ifdef __cplusplus
}
#endif


#endif
