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

📄 todo.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
📖 第 1 页 / 共 5 页
字号:
	lst = GetObjectPtr (OptionsSortByList);
	label = LstGetSelectionText (lst, listItem);
	ctl = GetObjectPtr (OptionsSortByTrigger);
	CtlSetLabel (ctl, label);
	LstSetSelection (lst, listItem);


	// Initialize the checkboxes in the dialog box.
	SetObjectValue (OptionsShowCompleted, ShowCompletedItems);
	SetObjectValue (OptionsShowDueItems, ShowOnlyDueItems);
	SetObjectValue (OptionsChangeDueDate, ChangeDueDate);
	SetObjectValue (OptionsShowDueDates, ShowDueDates);
	SetObjectValue (OptionsShowPriorities, ShowPriorities);
	SetObjectValue (OptionsShowCategories, ShowCategories);
}


/***********************************************************************
 *
 * FUNCTION:    OptionsHandleEvent
 *
 * DESCRIPTION: This routine is the event handler for the "Options
 *              Dialog Box" of the ToDo application.
 *
 * PARAMETERS:  event  - a pointer to an EventType structure
 *
 * RETURNED:    true if the event was handled and should not be passed
 *              to a higher level handler.
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	5/23/95		Initial Revision
 *
 ***********************************************************************/
static Boolean OptionsHandleEvent (EventPtr event)
{
	Boolean handled = false;
	FormPtr frm;

	if (event->eType == ctlSelectEvent)
		{
		switch (event->data.ctlSelect.controlID)
			{
			case OptionsOkButton:
				OptionsApply ();
				FrmReturnToForm (ListView);
				FrmUpdateForm (ListView, updateDisplayOptsChanged);
				handled = true;
				break;

			case OptionsCancelButton:
				FrmReturnToForm (ListView);
				handled = true;
				break;
				
			}
		}

	else if (event->eType == frmOpenEvent)
		{
		frm = FrmGetActiveForm ();
		OptionsInit ();
		FrmDrawForm (frm);
		handled = true;
		}

	return (handled);
}


#pragma mark ----------------
/***********************************************************************
 *
 * FUNCTION:    DetailsSetDateTrigger
 *
 * DESCRIPTION: This routine sets the date trigger, in the details dialog,
 *              to the specified date.  
 *
 * PARAMETERS:  year	  - years (since 1904)
 *              month  - months (1-12)
 *              day    - days (1-31)
 *
 * RETURNED:    nothing
 *
 * NOTES:
 *      This routine assumes that the memory allocated for the label of 
 *      the due date trigger is large enough to hold the largest possible
 *      label.  This label memory is reserved by initializing the label
 *      in the resource file.     
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	5/31/95	Initial Revision
 *
 ***********************************************************************/
static void DetailsSetDateTrigger (DateType date)
{
	Int16 dayOfWeek;
	Char * str;
	Char* label;
	ListPtr lst;
	ControlPtr ctl;
	
	lst = GetObjectPtr (DetailsDueDateList);
	LstSetSelection (lst, noDueDateItem);

	ctl = GetObjectPtr (DetailsDueDateTrigger);
	label = (Char *)CtlGetLabel (ctl);

	// Minus one means no date.  Set the label of the trigger to the 
	// first choice of the popup list, which is "no date".
	if (DateToInt (date) == toDoNoDueDate)
		{
		str = LstGetSelectionText (lst, noDueDateItem);
		StrCopy (label, str);
		CtlSetLabel (ctl, label);
		LstSetSelection (lst, noDueDateItem);
		}

	// Format the date into a string and set it as the label of the trigger.
	else
		{	
		// Format the date into a string.
		dayOfWeek = DayOfWeek (date.month, date.day, date.year+firstYear);
		DateToDOWDMFormat (date.month, date.day, date.year+firstYear,
			DateFormat, label);
		
		CtlSetLabel (ctl, label);
		LstSetSelection (lst, selectDateItem);
		}
}


/***********************************************************************
 *
 * FUNCTION:    DetailsSelectCategory
 *
 * DESCRIPTION: This routine handles selection, creation and deletion of
 *              categories in the Details Dialog.  
 *
 * PARAMETERS:  category - the current catagory, returns to new
 *                         category
 *
 * RETURNED:    true if the category was changed in a way that 
 *              require the list view to be redrawn.
 *
 *              The following global variables are modified:
 *							CategoryName
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	03/10/95	Initial Revision
 *			gap	08/13/99	Update to use new constant categoryDefaultEditCategoryString.
 *			mchen 12/20/00 Changed to sort after CategorySelect() returns
 *
 ***********************************************************************/
static Boolean DetailsSelectCategory (UInt16* category)
{
	Char* name;
	Boolean categoryEdited;
	
	name = (Char *)CtlGetLabel (GetObjectPtr (DetailsCategoryTrigger));

	categoryEdited = CategorySelect (ToDoDB, FrmGetActiveForm (),
		DetailsCategoryTrigger, DetailsCategoryList,
		false, category, name, 1, categoryDefaultEditCategoryString);
		
	// we can't tell if other categories have been changed so we MUST
	// resort no matter what because we use category names as one of
	// our sort fields.  CategorySelect() only returns true if the
	// current category has changed, but we care about ALL categories.
	ToDoSort(ToDoDB);
		
	return (categoryEdited);
}


/***********************************************************************
 *
 * FUNCTION:    DetailsDeleteToDo
 *
 * DESCRIPTION: This routine deletes a ToDo item.  This routine is called 
 *              when the delete button in the details dialog is pressed.
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    true if the record was delete or archived.
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	5/1/95		Initial Revision
 *
 ***********************************************************************/
static Boolean DetailsDeleteToDo (void)
{
	UInt16 recordNum;
	Boolean empty;
	MemHandle recordH;
	ToDoDBRecordPtr recordP;
		
	recordNum = CurrentRecord;

	// Check if the record is empty. If it is, clear the edit state, 
	// this will delete the current record if it is blank.
	recordH = DmQueryRecord (ToDoDB, recordNum);
	recordP = MemHandleLock (recordH);
	empty = (! recordP->description) && (! *GetToDoNotePtr(recordP));
	MemHandleUnlock (recordH);

	if (empty)
		{
		ClearEditState ();
		return (true);
		}
		
	// Display an alert to confirm the delete operation, and delete the
	// record if the alert is confirmed.
	if (!  DeleteRecord (recordNum) )
		return (false);
	
	ItemSelected = false;
	
	return (true);
}


/***********************************************************************
 *
 * FUNCTION:    DetailsApply
 *
 * DESCRIPTION: This routine applies the changes made in the Details Dialog.
 *
 * PARAMETERS:  category        - new catagory
 *              dueDateP        - new due date
 *              categoryEdited  - true if current category has been moved, 
 *              deleted, renamed, or merged with another category
 *
 * RETURNED:    code which indicates how the ToDo list was changed,  this
 *              code is sent as the update code in a frmUpdate event.
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	3/10/95	Initial Revision
 *			kcr	10/9/95	Added 'private records' alert
 *			rbb	4/14/99	Uses GetObjectValue (trimming a few bytes of code)
 *			jmp	11/15/99	Don't clear the edit state here as we could be
 *								going into NoteView, and NoteView needs to be
 *								associated with a record.  Instead, just return
 *								update code, and let ListViewUpdateDisplay() handle
 *								clearing the edit state if necessary.
 *
 ***********************************************************************/
static UInt16 DetailsApply (UInt16 category, DateType * dueDateP, 
	Boolean categoryEdited)
{
	FormPtr				frm;
	UInt16				attr;
	UInt16 				index;
	UInt16 				updateCode = 0;
	UInt16 				curPriority;
	UInt16 				newPriority;
	Boolean  			secret;
	Boolean				dirty = false;
	MemHandle 			recordH;
	DateType				curDueDate;
	ToDoDBRecordPtr	toDoRec;

	// Get the secret attribute of the current record.
	DmRecordInfo (ToDoDB, CurrentRecord, &attr, NULL, NULL);	

	// Get the priority setting from the dialog and compare it with the
	// priortity value in the current record.
	frm = FrmGetActiveForm ();
	index = FrmGetControlGroupSelection (frm, DetailsPrioritiesGroup);
	
	recordH = DmQueryRecord (ToDoDB, CurrentRecord);
	ErrFatalDisplayIf ((! recordH), "Record not found");

	toDoRec = (ToDoDBRecordPtr) MemHandleLock (recordH);
	curPriority = toDoRec->priority & priorityOnly;
	MemHandleUnlock (recordH);
	
	newPriority = FrmGetObjectId (frm, index) - DetailsPriority1Trigger + 1;

	if (curPriority != newPriority)
		{		
		ToDoChangeRecord (ToDoDB, &CurrentRecord, toDoPriority, &newPriority);
		updateCode |= updateItemMove;
		dirty = true;
		}

	// Compare the due date setting in the dialog with the due date in the
	// current record.  Update the record if necessary.
	recordH = DmQueryRecord (ToDoDB, CurrentRecord);
	ErrFatalDisplayIf ((! recordH), "Record not found");

	toDoRec = (ToDoDBRecordPtr) MemHandleLock (recordH);
	curDueDate = toDoRec->dueDate;
	MemHandleUnlock (recordH);

	if (MemCmp (dueDateP, &curDueDate, sizeof (DateType)))
		{
		ToDoChangeRecord (ToDoDB, &CurrentRecord, toDoDueDate, dueDateP);
		updateCode |= updateItemMove;
		dirty = true;
		}

	// Compare the current category to the category setting of the dialog.
	// Update the record if the categories are different.	
	if ((attr & dmRecAttrCategoryMask) != category)
		{
		ToDoChangeRecord (ToDoDB, &CurrentRecord, toDoCategory, &category);

		attr &= ~dmRecAttrCategoryMask;
		attr |= category;
		dirty = true;

		updateCode |= updateItemMove;
		}

	// Get the current setting of the secret checkbox and compare it the
	// the setting of the record.  Update the record if the values 
	// are different.
	secret = GetObjectValue (DetailsSecretCheckbox);
	if (((attr & dmRecAttrSecret) == dmRecAttrSecret) != secret)
		{
		if (PrivateRecordVisualStatus > showPrivateRecords)
			{
			updateCode |= updateItemHide;
			}

		else if (secret)
			FrmAlert (privateRecordInfoAlert);

		dirty = true;
		if (secret)
			attr |= dmRecAttrSecret;
		else
			attr &= ~dmRecAttrSecret;
		}

	// If the current category was deleted, renamed, or merged with
	// another category, then the list view needs to be redrawn.
	if (categoryEdited)
		{
		CurrentCategory = category;
		updateCode |= updateCategoryChanged;
		}

	// Save the new category and/or secret status, and mark the record dirty.
	if (dirty)
		{
		attr |= dmRecAttrDirty;
		DmSetRecordInfo (ToDoDB, CurrentRecord, &attr, NULL);
		}

	return (updateCode);
}


/***********************************************************************
 *
 * FUNCTION:    DetailsInit
 *
 * DESCRIPTION: This routine initializes the Details Dialog.  
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	3/10/95	Initial Revision
 *			rbb	4/14/99	Uses SetObjectValue (trimming a few bytes of code)
 *
 ***********************************************************************/
static void DetailsInit (UInt16* categoryP, DateType * dueDateP)
{
	UInt16 attr;
	UInt16 category;
	UInt16 priority;
	Char* name;
	ControlPtr ctl;
	MemHandle recordH;
	ToDoDBRecordPtr	toDoRec;

	// If the record is marked secret, turn on the secret checkbox.
	DmRecordInfo (ToDoDB, CurrentRecord, &attr, NULL, NULL);
	SetObjectValue (DetailsSecretCheckbox, (attr & dmRecAttrSecret) != 0);

	// Set the label of the category trigger.
	category = attr & dmRecAttrCategoryMask;
	ctl = GetObjectPtr (DetailsCategoryTrigger);
	name = (Char *)CtlGetLabel (ctl);
	CategoryGetName (ToDoDB, category, name);
	CategorySetTriggerLabel (ctl, name);

	// Get a pointer to the ToDo record.
	recordH = DmQueryRecord (ToDoDB, CurrentRecord);
	ErrFatalDisplayIf ((! recordH), "Record not found");

	toDoRec = (ToDoDBRecordPtr) MemHandleLock (recordH);
	
	// Set the priority push button.
	priority = toDoRec->priority & priorityOnly;
	SetObjectValue ((DetailsPriority1Trigger + priority - 1), true);
	
	// Set the due date trigger.
	DetailsSetDateTrigger (toDoRec->dueDate);

	// Return the current category and due date.
	*categoryP = category;
	*dueDateP = toDoRec->dueDate;

	// Unlock the ToDo record
	MemHandleUnlock (recordH);
}


/***********************************************************************
 *
 * FUNCTION:    DetailsHandleEvent
 *
 * DESCRIPTION: This routine is the event handler for the "Details
 *              Dialog Box" of the ToDo application.
 *
 * PARAMETERS:  event  - a pointer to an EventType structure
 *
 * RETURNED:    true if the event was handled and should not be passed
 *              to a higher level handler.
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	2/21/95	Initial Revision
 *			jmp	9/17/99	Use NewNoteView instead of NoteView.
 *
 ***********************************************************************/
static Boolean DetailsHandleEvent (EventPtr event)
{
	static UInt16 		category;
	static DateType 	dueDate;
	static Boolean		categoryEdited;

	UInt16 updateCode;
	Boolean handled = false;
	FormPtr frm;

	if (event->eType == ctlSelectEvent)
		{

⌨️ 快捷键说明

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