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

📄 addrnote.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
 *
 * Copyright (c) 1995-2003 PalmSource, Inc. All rights reserved.
 *
 * File: AddrNote.c
 *
 * Release: Palm OS 5 SDK (68K) R3.
 *
 * Description:
 *  This is the Address Book Note screen
 *
 *****************************************************************************/

#include "AddrNote.h"
#include "Address.h"
#include "AddrTools.h"
#include "AddressRsc.h"

#include <Category.h>
#include <UIResources.h>
#include <StringMgr.h>
#include <PhoneLookup.h>
#include <TraceMgr.h>


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

static void		PrvNoteViewInit (FormPtr frm);
static void		PrvNoteViewDrawTitleAndForm (FormPtr frm);
static void		PrvNoteViewUpdateScrollBar (void);
static void		PrvNoteViewLoadRecord (void);
static void		PrvNoteViewSave (void);
static Boolean	PrvNoteViewDeleteNote (void);
static Boolean	PrvNoteViewDoCommand (UInt16 command);
static void		PrvNoteViewScroll (Int16 linesToScroll, Boolean updateScrollbar);
static void		PrvNoteViewPageScroll (WinDirectionType direction);


/***********************************************************************
 *
 * FUNCTION:    NoteViewHandleEvent
 *
 * DESCRIPTION: This routine is the event handler for the NoteView
 *              of the ToDo application.
 *
 * PARAMETERS:  event  - a pointer to an EventType structure
 *
 * RETURNED:    true if the event has handled and should not be passed
 *              to a higher level handler.
 *
 * REVISION HISTORY:
 *			Name	Date			Description
 *			----	----			-----------
 *       art  	6/5/95   	Initial Revision
 *			jmp	9/8/99		Made this routine more consistent with the
 *									other built-in apps that have it.
 *			jmp	9/27/99		Combined NoteViewDrawTitle() & FrmUpdateForm()
 *									into a single routine that is now called
 *									PrvNoteViewDrawTitleAndForm().
 *			peter	09/15/00		Disable attention indicator because title is custom.
 *
 ***********************************************************************/
Boolean NoteViewHandleEvent (EventType * event)
{
	FormType* frmP;
	Boolean handled = false;
	FieldPtr fldP;


	switch (event->eType)
	{
		case frmOpenEvent:
			TraceOutput(TL(appErrorClass, "NoteViewHandleEvent() - frmOpenEvent"));
			frmP = FrmGetActiveForm ();
			PrvNoteViewInit (frmP);
			PrvNoteViewDrawTitleAndForm (frmP);
			PrvNoteViewUpdateScrollBar ();
			FrmSetFocus (frmP, FrmGetObjectIndex (frmP, NoteField));
			handled = true;
			break;
	
		case frmCloseEvent:
			TraceOutput(TL(appErrorClass, "NoteViewHandleEvent() - frmCloseEvent"));

			AttnIndicatorEnable(true);		// Custom title doesn't support attention indicator.

			if ( UnnamedRecordStringPtr != 0 )
			{
				MemPtrUnlock(UnnamedRecordStringPtr);
				UnnamedRecordStringPtr = NULL;
			}

			if ( UnnamedRecordStringH != 0 )
			{
				TraceOutput(TL(appErrorClass, "NoteViewHandleEvent() - frmCloseEvent - freeing UnnamedRecordStringH"));
				DmReleaseResource(UnnamedRecordStringH);
				UnnamedRecordStringH = NULL;
			}
			
			if ( FldGetTextHandle (ToolsGetObjectPtr (NoteField)))
				PrvNoteViewSave ();
			break;
	
		case keyDownEvent:
			if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr))
			{
				PrvNoteViewSave ();
				FrmGotoForm (ListView);
				handled = true;
			}
	
			else if (EvtKeydownIsVirtual(event))
			{
				if (event->data.keyDown.chr == vchrPageUp)
				{
					PrvNoteViewPageScroll (winUp);
					handled = true;
				}
				else if (event->data.keyDown.chr == vchrPageDown)
				{
					PrvNoteViewPageScroll (winDown);
					handled = true;
				}
			}
			break;
	
	
		case ctlSelectEvent:
			switch (event->data.ctlSelect.controlID)
			{
				case NoteDoneButton:
					PrvNoteViewSave ();
		
					// When we return to the ListView highlight this record.
					if (PriorAddressFormID == ListView)
						ListViewSelectThisRecord = CurrentRecord;
		
					FrmGotoForm(PriorAddressFormID);
					handled = true;
					break;
		
				case NoteDeleteButton:
					if (PrvNoteViewDeleteNote ())
						FrmGotoForm (PriorAddressFormID);
		
					ListViewSelectThisRecord = noRecord;
					handled = true;
					break;
		
				default:
					break;
			}
			break;
	
		case fldChangedEvent:
			frmP = FrmGetActiveForm ();
			PrvNoteViewUpdateScrollBar ();
			handled = true;
			break;
	
		case menuEvent:
			return PrvNoteViewDoCommand (event->data.menu.itemID);
	
		case frmGotoEvent:
			frmP = FrmGetActiveForm ();
			CurrentRecord = event->data.frmGoto.recordNum;
			PrvNoteViewInit(frmP);
			fldP = ToolsGetFrmObjectPtr(frmP, NoteField);
			FldSetScrollPosition(fldP, event->data.frmGoto.matchPos);
			FldSetSelection(fldP, event->data.frmGoto.matchPos,
							event->data.frmGoto.matchPos + event->data.frmGoto.matchLen);
			PrvNoteViewDrawTitleAndForm (frmP);
			PrvNoteViewUpdateScrollBar();
			FrmSetFocus(frmP, FrmGetObjectIndex(frmP, NoteField));
			handled = true;
			break;
	
	
		case frmUpdateEvent:
			if (event->data.frmUpdate.updateCode & updateFontChanged)
			{
				fldP = ToolsGetObjectPtr(NoteField);
				FldSetFont(fldP, NoteFont);
				PrvNoteViewUpdateScrollBar();
			}
			else
			{
				// Handle the case that form is not active (frmRedrawUpdateCode)
				frmP = FrmGetFormPtr(NewNoteView);
				PrvNoteViewDrawTitleAndForm(frmP);
			}
			handled = true;
			break;
	
		case sclRepeatEvent:
			PrvNoteViewScroll (event->data.sclRepeat.newValue - event->data.sclRepeat.value, false);
			break;
	
		default:
			break;
	}

	return (handled);
}


/***********************************************************************
 *
 * FUNCTION:    NoteViewCreate
 *
 * DESCRIPTION: Make sure there is a note field to edit.  If one doesn't
 * exist make one.
 *
 *   The main reason this routine exists is to make sure we can edit a note
 * before we close the current form.
 *
 * PARAMETERS:  CurrentRecord set
 *
 * RETURNED:    true if a note field exists to edit
 *
 * REVISION HISTORY:
 *         Name   Date      Description
 *         ----   ----      -----------
 *         roger   10/19/95   Initial Revision
 *         ryw      2/18/00  Added cast to satisfy const cstring checking, should be safe
 *
 ***********************************************************************/
Boolean NoteViewCreate (void)
{
	AddrDBRecordType record;
	AddrDBRecordFlags bit;
	MemHandle recordH;
	Err err;


	AddrDBGetRecord (AddrDB, CurrentRecord, &record, &recordH);


	// Since we are going to edit in place, add a note field if there
	// isn't one
	if (!record.fields[note])
	{
		record.fields[note] = (char *)"";
		bit.allBits = (UInt32)1 << note;
		err = AddrDBChangeRecord(AddrDB, &CurrentRecord, &record, bit);
		if (err)
		{
			MemHandleUnlock(recordH);
			FrmAlert(DeviceFullAlert);
			return false;            // can't make an note field.
		}

	}
	else
	{
		MemHandleUnlock(recordH);
	}

	return true;                  // a note field exists.
}


/***********************************************************************
 *
 * FUNCTION:    NoteViewDelete
 *
 * DESCRIPTION: Deletes the note field from the current record.
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *         Name   Date      Description
 *         ----   ----      -----------
 *         roger   6/21/95   Initial Revision
 *
 ***********************************************************************/
void NoteViewDelete (void)
{
	AddrDBRecordType record;
	MemHandle recordH;
	AddrDBRecordFlags changedField;
	Err err;


	AddrDBGetRecord (AddrDB, CurrentRecord, &record, &recordH);
	record.fields[note] = NULL;
	changedField.allBits = (UInt32)1 << note;
	err = AddrDBChangeRecord(AddrDB, &CurrentRecord, &record, changedField);
	if (err)
	{
		MemHandleUnlock(recordH);
		FrmAlert(DeviceFullAlert);
		return;
	}


	// Mark the record dirty.
	ToolsDirtyRecord (CurrentRecord);
}

#pragma mark -

/***********************************************************************
 *
 * FUNCTION:    PrvNoteViewInit
 *
 * DESCRIPTION: This routine initials the Edit View form.
 *
 * PARAMETERS:  frm - pointer to the Edit View form.
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *				Name	Date		Description
 *	        	----	----		-----------
 *				art   6/5/95	Initial Revision
 *				jmp	9/23/99	Eliminate code to hide unused font controls
 *									now that we're using a NoteView form that doesn't
 *									have them anymore.
 *				peter	09/20/00	Disable attention indicator because title is custom.
 *
 ***********************************************************************/
void PrvNoteViewInit( FormType* frmP )
{
	FieldPtr       fld;
	FieldAttrType  attr;

	AttnIndicatorEnable(false);		// Custom title doesn't support attention indicator.
	PrvNoteViewLoadRecord ();

	// Have the field send events to maintain the scroll bar.
	fld = ToolsGetFrmObjectPtr(frmP, NoteField);
	FldGetAttributes (fld, &attr);
	attr.hasScrollBar = true;
	FldSetAttributes (fld, &attr);
}


/***********************************************************************
 *
 * FUNCTION:    PrvNoteViewDrawTitleAndForm
 *
 * DESCRIPTION: Draw the form and the title of the note view.  The title should be
 * the names that appear for the record on the list view.
 *
 * PARAMETERS:  frm, FormPtr to the form to draw
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *         Name   Date      Description
 *         ----   ----      -----------
 *         roger  6/21/95   Initial Revision
 *         jmp    9/27/99   Square off the NoteView title so that it covers up
 *                          the blank Form title used to trigger the menu on taps
 *                          to the title area.  Also, set the NoteView title's color
 *                          to match the standard Form title colors.  Eventually, we
 *                          should add a variant to Forms that allows for NoteView
 *                          titles directly.  This "fixes" bug #21610.
 *         jmp    9/29/99   Fix bug #22412.  Ensure that title-length metrics are
 *                          computed AFTER the NoteView's title font has been set.
 *         jmp   12/02/99   Fix bug #24377.  Don't call WinScreenUnlock() if WinScreenLock()
 *                          fails.
 *			  peter 05/26/00	 Ensure font height isn't used until font is set.
 *
 ***********************************************************************/
void PrvNoteViewDrawTitleAndForm (FormPtr frm)
{
	Coord x, y;
	Int16 fieldSeparatorWidth;
	Int16 shortenedFieldWidth;
	Char * name1;
	Char * name2;
	Int16 name1Length;
	Int16 name2Length;
	Int16 name1Width;
	Int16 name2Width;
	Int16 nameExtent;
	Coord formWidth;
	RectangleType r;
	FontID curFont;
	RectangleType eraseRect,drawRect;

⌨️ 快捷键说明

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