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

📄 memomain.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
📖 第 1 页 / 共 5 页
字号:

	// Get the current record.
	memoRec = DmGetRecord (MemoDB, CurrentRecord);
	ErrFatalDisplayIf ((! memoRec), "Bad record");

	// Set the font used by the memo field.
	FldSetFont (fld, EditFont);

	FldSetTextHandle (fld, memoRec);
	FldSetScrollPosition (fld, EditScrollPosition);

	// Set the global variable that keeps track of the current category
	// to the category of the current record.
	CurrentCategory = attr & dmRecAttrCategoryMask;

	// If the record is secret and secret records are hidden, then the record isn't
	// accounted for by MemosInCategory.  Adjust it, and EditViewSaveRecord will
	// adjust when done with the record.
	if ((PrivateRecordVisualStatus == hidePrivateRecords) && (attr & dmRecAttrSecret))
		MemosInCategory++;

	// Set the view's title
	EditViewSetTitle ();

	// Set the label that contains the note's category.
	ctl = GetObjectPtr (EditCategoryTrigger);
	CategoryGetName (MemoDB, CurrentCategory, CategoryName);
	CategorySetTriggerLabel (ctl, CategoryName);

	EditViewUpdateScrollBar ();
}


/***********************************************************************
 *
 * FUNCTION:    EditViewSaveRecord
 *
 * DESCRIPTION: This routine save a memo record to the memo database or
 *				deletes it if it's empty.
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	2/21/95	Initial Revision
 *			kcr	11/16/95	use DmReleaseRecord to set dirty attribute
 *			jmp	9/29/99	Use FrmGetFormPtr() & FrmGetObjectIndex() instead of
 *								GetObjectPtr() because GetObjectPtr() calls FrmGetActiveForm(),
 *								and FrmGetActiveForm() may return a form that isn't the one we
 *								want when other forms are up when we are called.
 *								Fixes bug #22418.
 *
 ***********************************************************************/
static void EditViewSaveRecord (void)
{
	UInt16	attr;
	Char *	ptr;
	Boolean 	empty;
	Boolean	dirty;
	FieldPtr fld;
	FormPtr	frm;

	// Find out if the field has been modified or if it's empty.
	frm = FrmGetFormPtr (EditView);
	fld = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, EditMemoField));
	ptr = FldGetTextPtr (fld);
	dirty = FldDirty (fld);
	empty = (*ptr == 0);

	FldReleaseFocus (fld);

	// Release any free space in the memo field.
	FldCompactText (fld);

	// Clear the handle value in the field, otherwise the handle
	// will be free when the form is disposed of.
	FldSetTextHandle (fld, 0);

	// If there's data in an existing record, mark it dirty if
	// necessary and release it.
	if (! empty)
	{
		DmRecordInfo (MemoDB, CurrentRecord, &attr, NULL, NULL);

		if (PrivateRecordVisualStatus == hidePrivateRecords && (attr & dmRecAttrSecret))
			MemosInCategory--;

		DmReleaseRecord (MemoDB, CurrentRecord, dirty);

		// Move the current record to the correct sort position.
		if (dirty)
			MemoSortRecord (MemoDB, &CurrentRecord);
	}

	// If the record is empty, delete it.
	else
	{
		if (dirty)
		{
			DmDeleteRecord (MemoDB, CurrentRecord);
			DmMoveRecord (MemoDB, CurrentRecord, DmNumRecords (MemoDB));
		}
		else
			DmRemoveRecord (MemoDB, CurrentRecord);

		CurrentRecord = noRecordSelected;
		MemosInCategory--;
	}

	ErrNonFatalDisplayIf(MemosInCategory > DmNumRecords(MemoDB), "invalid MemosInCategory");
}


/***********************************************************************
 *
 * FUNCTION:    EditViewChangeFont
 *
 * DESCRIPTION: This routine redisplay the memo in the font specified.
 *              It is called when one of the font push-buttons is presed.
 *
 * PARAMETERS:  controlID - id to button pressed.
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	2/21/95		Initial Revision
 *			kcr	10/20/95		handles two-button font change mechanism
 *
 ***********************************************************************/
static void EditViewChangeFont (void)
{
	FontID	fontID;
	FieldPtr fld;

	// Call the OS font selector to get the id of a font.
	fontID = FontSelect (EditFont);

	if (fontID != EditFont)
	{
		EditFont = fontID;

		// FldSetFont will redraw the field if it is visible.
		fld = GetObjectPtr (EditMemoField);
		FldSetFont (fld, fontID);
	}

	EditViewUpdateScrollBar ();
}



/***********************************************************************
 *
 * FUNCTION:    EditViewDeleteRecord
 *
 * DESCRIPTION: This routine deletes a memo record..
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	2/21/95		Initial Revision
 *
 ***********************************************************************/
static Boolean EditViewDeleteRecord (void)
{
	FormPtr  frm;
	FieldPtr fld;
	Char *  ptr;
	UInt16 ctlIndex;
	UInt16 buttonHit;
	FormPtr alert;
	Boolean empty;
	Boolean saveBackup;


	frm = FrmGetFormPtr (EditView);
	fld = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, EditMemoField));

	// Find out if the field is empty.
	ptr = FldGetTextPtr (fld);
	empty = (*ptr == 0);

	// Display an alert to confirm the operation.
	if (!empty)
	{
		alert = FrmInitForm (DeleteMemoDialog);

		ctlIndex = FrmGetObjectIndex (alert, DeleteMemoSaveBackup);
		FrmSetControlValue (alert, ctlIndex, SaveBackup);
		buttonHit = FrmDoDialog (alert);
		saveBackup = FrmGetControlValue (alert, ctlIndex);;

		FrmDeleteForm (alert);

		if (buttonHit == DeleteMemoCancel)
			return (false);

		SaveBackup = saveBackup;
	}

	// Clear the handle value in the field, otherwise the handle
	// will be free when the form is disposed of.
	FldSetTextHandle (fld, 0);

	// Delete or archive the record.
	if (empty && (! FldDirty (fld)))
	{
		DmRemoveRecord (MemoDB, CurrentRecord);
	}
	else
	{
		if (SaveBackup)
			DmArchiveRecord (MemoDB, CurrentRecord);
		else
			DmDeleteRecord (MemoDB, CurrentRecord);
		DmMoveRecord (MemoDB, CurrentRecord, DmNumRecords (MemoDB));
	}

	MemosInCategory--;
	CurrentRecord = noRecordSelected;

	ErrNonFatalDisplayIf(MemosInCategory > DmNumRecords(MemoDB), "invalid MemosInCategory");

	return (true);
}


/***********************************************************************
 *
 * FUNCTION:		EditViewDoCommand
 *
 * DESCRIPTION:	This routine performs the menu command specified.
 *
 * PARAMETERS:		command  - menu item id
 *
 * RETURNED:    	True if we handled the command.
 *
 *	HISTORY:
 *		03/29/95	art	Created by Art Lamb.
 *		11/07/95	kcr	converted to common about box
 *		08/21/99	kwk	Deleted page top/bottom commands.
 *		11/04/99	jmp	To prevent other sublaunch issues, remind ourselves
 *							that we've sublaunched already into PhoneNumberLookup().
 *
 ***********************************************************************/
static Boolean EditViewDoCommand (UInt16 command)
{
	FieldPtr fld;
	FormPtr frm;
	Boolean handled = true;

	switch (command)
	{
	case NewMemoCmd:
		EditViewSaveRecord ();
		CreateRecord ();
		EditScrollPosition = 0;
		if (CurrentRecord != noRecordSelected)
		{
			EditViewLoadRecord (FrmGetActiveForm ());
			fld = GetFocusObjectPtr ();
			if (fld) FldGrabFocus (fld);
		}
		else
			FrmGotoForm (ListView);
		break;

	case DeleteMemoCmd:
		if (EditViewDeleteRecord ())
			FrmGotoForm (ListView);
		break;

	case BeamMemoCmd:
	case SendMemoCmd:
		fld = GetObjectPtr (EditMemoField);
		if (FldGetTextLength(fld) > 0)
		{
			EditViewSaveRecord();
			MemoSendRecord(MemoDB, CurrentRecord, (command == BeamMemoCmd ? exgBeamPrefix : exgSendPrefix));

			// Redisplay the record.  If the IR loopback mechanism sends the
			// record to this app the goto action code closes all forms and
			// send a frmGotoEvent.  Load the record again only if the form
			// still exits.
			frm = FrmGetActiveForm ();
			if (frm)
				EditViewLoadRecord (frm);
		}
		else
			FrmAlert(NoDataToBeamAlert);
		break;
		/*
		 case BeamCategoryCmd:
		 case SendCategoryCmd:
		 fld = GetObjectPtr (EditMemoField);
		 if (FldGetTextLength(fld) > 0)
		 {
		 FldCompactText (fld);
		 MemoSendCategory(MemoDB, CurrentCategory, (command == BeamCategoryCmd ? exgBeamPrefix : exgSendPrefix), (command == BeamCategoryCmd ? NoDataToBeamAlert : NoDataToSendAlert));
		 }
		 else
		 FrmAlert(NoDataToBeamAlert);
		 break;
		 */

	case EditOptionsFontsCmd:
		EditViewChangeFont ();
		break;

	case EditOptionPhoneLookupCmd:
		fld = GetObjectPtr (EditMemoField);
		if (fld)
		{
			InPhoneLookup = true;
			PhoneNumberLookup (fld);
			InPhoneLookup = false;
		}
		break;

	case EditOptionsAboutCmd:
		AbtShowAbout (sysFileCMemo);
		break;

	default:
		handled = false;
	}

	return (handled);
}


/***********************************************************************
 *
 * FUNCTION:    EditViewScroll
 *
 * DESCRIPTION: This routine scrolls the memo edit view a page or a
 *              line at a time.
 *
 * PARAMETERS:  linesToScroll - the number of lines to scroll,
 *						positive for winDown,
 *						negative for winUp
 *					 updateScrollbar - force a scrollbar update?
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	7/1/96	Initial Revision
 *			grant 2/4/99	Use EditViewUpdateScrollBar()
 *
 ***********************************************************************/
static void EditViewScroll (Int16 linesToScroll, Boolean updateScrollbar)
{
	UInt16				blankLines;
	FieldPtr			fld;

	fld = GetObjectPtr (EditMemoField);
	blankLines = FldGetNumberOfBlankLines (fld);

	if (linesToScroll < 0)
		FldScrollField (fld, -linesToScroll, winUp);
	else if (linesToScroll > 0)
		FldScrollField (fld, linesToScroll, winDown);

	// If there were blank lines visible at the end of the field
	// then we need to update the scroll bar.
	if (blankLines || updateScrollbar)
	{
		ErrNonFatalDisplayIf(blankLines && linesToScroll > 0, "blank lines when scrolling winDown");

		EditViewUpdateScrollBar();
	}
}


/***********************************************************************
 *
 * FUNCTION:    EditViewPageScroll
 *
 * DESCRIPTION: This routine scrolls the message a page winUp or winDown.
 *					 When the top of a memo is visible, scrolling up will
 *              display the display the botton of the previous memo.
 *              If the bottom of a memo is visible, scrolling down will
 *              display the top of the next memo.
 *
 * PARAMETERS:   direction     winUp or winDown
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	7/1/96	Initial Revision
 *			grant 2/4/99	Use EditViewScroll() to do actual scrolling.
 *
 ***********************************************************************/
static void EditViewPageScroll (WinDirectionType direction)
{
	Int16 seekDirection;
	UInt16 category;
	UInt16 recordNum;
	UInt32 uniqueID;
	UInt16 linesToScroll;
	FieldPtr fld;
	UInt16	attr;

	fld = GetObjectPtr (EditMemoField);

	if (FldScrollable (fld, direction))
	{
		linesToScroll = FldGetVisibleLines (fld) - 1;

		if (direction == winUp)
			linesToScroll = -linesToScroll;

		EditViewScroll(linesToScroll, true);

		return;
	}


	// Move to the next or previous memo.
	if (direction == winUp)
	{
		seekDirection = dmSeekBackward;
		EditScrollPosition = maxFieldTextLen;
	}
	else
	{
		seekDirection = dmSeekForward;
		EditScrollPosition = 0;
	}

	if (ShowAllCategories)
		category = dmAllCategories;
	else
		category = CurrentCategory;

	recordNum = CurrentRecord;

	//while to skip masked records. Even if the body never executes, we'll have done a DmSeekRecordInCategory
	while (!DmSeekRecordInCategory (MemoDB, &recordNum, 1, seekDirection, category) &&
		   !DmRecordInfo (MemoDB, recordNum, &attr, NULL, NULL) &&
		   ((attr & dmRecAttrSecret) && PrivateRecordVisualStatus == maskPrivateRecords))
	{
	}

	if (recordNum == CurrentRecord) return;

	// Don't show first/last record if it's private and we're masking.
	if (!DmRecordInfo (MemoDB, recordNum, &attr, NULL, NULL) &&
		((attr & dmRecAttrSecret) && PrivateRecordVisualStatus == maskPriva

⌨️ 快捷键说明

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