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

📄 datebook.c

📁 我的Palm OS 5 SDK zhCN_PIMApps代码。 使用codewarrior 开发环境
💻 C
📖 第 1 页 / 共 4 页
字号:
       
	
	// The only place the following define is used is in the Jamfile for this application.
	// It's sole purpose is to provide a way to check if cross segment calls are being made
	// when application globals are unavailable.
#ifndef SINGLE_SEGMENT_CHECK
	Boolean launched;

	// Launch code sent by the launcher or the datebook button.
	if (cmd == sysAppLaunchCmdNormalLaunch)
		{
		error = StartApplication ();
		if (error) return (error);
		
		// If the user previously left the Datebook while viewing the agenda,
		// return there. Otherwise, go to the day view
		error = FtrGet (sysFileCDatebook, recentFormFeature, &defaultForm);
		if (error)
			{
			defaultForm = defaultRecentForm;
			}
			
		FrmGotoForm (defaultForm);
		EventLoop ();
		StopApplication ();
		}


	// This action code is a DateBook specific custom launch code.
	// It will always require that the app launches as it is a result
	// of a SysUIAppSwitch call.
	else if (cmd == appLaunchCmdAlarmEventGoto)
		{
			error = StartApplication ();
			if (error) return (error);

			GoToAlarmItem (*((UInt32*)cmdPBP));

			EventLoop ();
			StopApplication ();	
		}

	

	// This action code might be sent to the app when it's already running
	// if the use hits the "Go To" button in the Find Results dialog box.
	else if (cmd == sysAppLaunchCmdGoTo)
		{
		launched = launchFlags & sysAppLaunchFlagNewGlobals;
		if (launched)
			{
			error = StartApplication ();
			if (error) return (error);

			GoToItem ((GoToParamsPtr) cmdPBP, launched);

			EventLoop ();
			StopApplication ();	
			}
		else
			GoToItem ((GoToParamsPtr) cmdPBP, launched);
		}
#else
	if (false) {}
#endif

	//////////////////////////////////////////////////////////////////////////////////
	//
	// WARNING! Launch codes below this point can be called from a context where
	// 			application globals are unavailable.
	//
	//////////////////////////////////////////////////////////////////////////////////

	// Launch code sent to running app before sysAppLaunchCmdFind
	// or other action codes that will cause data searches or manipulation.
	// We don't need to respond to this launch code because events are
	// edited in place.
//	else if (cmd == sysAppLaunchCmdSaveData)
//		{
//		FrmSaveAllForms ();
//		}
	

	// Launch code sent by text search.
	else if (cmd == sysAppLaunchCmdFind)
		{
		Search ((FindParamsPtr)cmdPBP);
		}
	

	// Launch code sent by sync application to notify the datebook 
	// application that its database was been synced.
	else if (cmd == sysAppLaunchCmdSyncNotify)
		{
		SyncNotification ();
		}
	

	// Launch code sent by Alarm Manager to notify the datebook 
	// application that an alarm has triggered.
	else if (cmd == sysAppLaunchCmdAlarmTriggered)
		{
		AlarmTriggered ((SysAlarmTriggeredParamType *)cmdPBP);
		}
	

	// Launch code sent when the system time is changed.
	else if (cmd == sysAppLaunchCmdTimeChange)
		{
		// reset the trigger for the next alarm to fire
		AlarmReset (false);
		
		// Remove any "future" alarms from the attention manager queue
		// (ie alarms that will trigger after the new time setting)
		UpdatePostedAlarms(DeviceTimeChanged);
		}
		

	// This action code is sent after the system is reset.  We use this time
	// to create our default database.  Note:  Unlike several other built-in
	// apps, we do not attempt to create an empty database if the default
	// database image doesn't exist.
	else if (cmd == sysAppLaunchCmdSystemReset) 
		{
		if (((SysAppLaunchCmdSystemResetType*)cmdPBP)->createDefaultDB)
			{
			MemHandle resH;
			
			resH = DmGet1Resource(sysResTDefaultDB, sysResIDDefaultDB);
			if (resH) 
				{
				DmCreateDatabaseFromImage(MemHandleLock(resH));
				MemHandleUnlock(resH);
				DmReleaseResource(resH);
				
				// set the backup bit on the new database
				SetDBBackupBit(NULL);
				}

			// Register to receive vcs files on hard reset.
			RegisterData();
			}

		if (! ((SysAppLaunchCmdSystemResetType*)cmdPBP)->hardReset)
			{
			AlarmReset (false);		// Find and install next upcoming alarm
			}
		}


   // Receive the record.  The app will parse the data and add it to the database.
   // This data should be displayed by the app.
	else if (cmd == sysAppLaunchCmdExgReceiveData) 
   	{
      UInt32 currentUID;
      
      // if our app is not active, we need to open the database 
      // the subcall flag is used here since this call can be made without launching the app
      if (!(launchFlags & sysAppLaunchFlagSubCall))
      	{
      	error = DateGetDatabase(&dbP, dmModeReadWrite);
      	}
      else
      	{
      	dbP = ApptDB;
      	
			// We don't delete the current record if it's empty because the user
			// could cancel the beam receive.
			
			// DateReceiveData() inserts the received record in sorted order. This may may change
			// the index of the current record. So we remember its UID here, and refresh our copy
			// of its index afterwards.
			if (CurrentRecord != noRecordSelected)
				DmRecordInfo(dbP, CurrentRecord, NULL, &currentUID, NULL);
      	}
      
      if (dbP != NULL)
      	{
			error = DateReceiveData(dbP, (ExgSocketPtr) cmdPBP);
			
	      if (launchFlags & sysAppLaunchFlagSubCall)
	      	{
				if (CurrentRecord != noRecordSelected)
					{
					if (DmFindRecordByID(dbP, currentUID, &CurrentRecord) != 0)
						CurrentRecord = noRecordSelected;	// Can't happen, but...
					
					// DOLATER dje -
					//		To fix the off-by-one error, we can decrement exgSocketP->goToParams.recordNum
					//		if it's after the current empty record in order to compensate for the
					//		current empty record getting deleted when we exit before the goto launch.
	      		}
	      	}
	      
			// The received event may have an alarm, reschedule the next alarm.
			RescheduleAlarms (dbP);

         if (!(launchFlags & sysAppLaunchFlagSubCall))
				DmCloseDatabase(dbP);
			}
		else
			error = exgErrAppError;	// DOLATER dje - use a new error code - "try again after switching apps"
		
		// If we can't open our database, return the error since it wasn't passed to ExgDisconnect
		return error;
		}

	else if (cmd == sysAppLaunchCmdExgPreview)
	{
		DateTransferPreview((ExgPreviewInfoType *)cmdPBP);
	}      
	// This action code is sent by the DesktopLink server when it create 
	// a new database.  We will initializes the new database.
	else if (cmd == sysAppLaunchCmdInitDatabase)
		{
		InitDatabase (((SysAppLaunchCmdInitDatabaseType*)cmdPBP)->dbP);
		}
		
	else if (cmd == sysAppLaunchCmdAttention)
		{
		AttentionBottleNeckProc((AttnLaunchCodeArgsType*)cmdPBP);
		}
		

	return (0);
}


#pragma mark ----------------
/***********************************************************************
 *
 * FUNCTION:    TimeToWait
 *
 * DESCRIPTION:	This routine calculates the number of ticks until the
 *						time display should be hidden.  If the time is not being
 *						displayed, we return evtWaitForever - a good default for
 *						EvtGetEvent.
 *
 *						If the agenda view is on display, return a delay of one
 *						second, allowing the title bar clock to update.
 *
 * PARAMETERS:  none
 *
 * RETURNED:    number of ticks to wait
 *						== evtWaitForever if we are not showing the time
 *						== 0 if time is up
 *
 *	NOTES:		Uses the global variables TimeDisplayed and TimeDisplayTick.
 *					TimeDisplayed is true when some temporary information is on
 *					display.  In that case, TimeDisplayTick is the time when the
 *					temporary display should go away.
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			grant	2/2/99	Initial Revision
 *			rbb	11/15/99	Added timeout for the agenda view 
 *
 ***********************************************************************/
Int32 TimeToWait()
{
	Int32 timeRemaining;
	
	if (FrmGetActiveFormID () == AgendaView)
		{
		return sysTicksPerSecond;
		}
	
	if (!TimeDisplayed)
		{
		return evtWaitForever;
		}
	
	timeRemaining = TimeDisplayTick - TimGetTicks();
	if (timeRemaining < 0)
		{
		timeRemaining = 0;
		}
	
	return timeRemaining;
}


/***********************************************************************
 *
 * FUNCTION:    ApplicationHandleEvent
 *
 * DESCRIPTION: This routine loads form resources and set the event
 *              handler for the form loaded.
 *
 * PARAMETERS:  event  - a pointer to an EventType structure
 *
 * RETURNED:    true if the event has handle and should not be passed
 *              to a higher level handler.
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	9/11/95	Initial Revision
 *			jmp	9/17/99	Use NewNoteVie instead of NoteView.
 *			rbb	11/12/99	Added recentFormFeature to pick default view on launch
 *
 ***********************************************************************/
static Boolean ApplicationHandleEvent (EventType* event)
{
	UInt16 formId;
	FormPtr frm;

	if (event->eType == frmLoadEvent)
		{
		// Load the form resource.
		formId = event->data.frmLoad.formID;
		frm = FrmInitForm (formId);
		FrmSetActiveForm (frm);		
		
		// Set the event handler for the form.  The handler of the currently
		// active form is called by FrmDispatchEvent each time is receives an
		// event.
		if (formId == DayView)
			FrmSetEventHandler (frm, DayViewHandleEvent);
			
		else if (formId == WeekView)
			FrmSetEventHandler (frm, WeekViewHandleEvent);
	
		else if (formId == MonthView)
			FrmSetEventHandler (frm, MonthViewHandleEvent);
	
		else if (formId == AgendaView)
			FrmSetEventHandler (frm, AgendaViewHandleEvent);
	
		else if (formId == NewNoteView)
			FrmSetEventHandler (frm, NoteViewHandleEvent);
	
		else if (formId == DetailsDialog)
			FrmSetEventHandler (frm, DetailsHandleEvent);

		else if (formId == RepeatDialog)
			FrmSetEventHandler (frm, RepeatHandleEvent);
	
		else if (formId == PreferencesDialog)
			FrmSetEventHandler (frm, PreferencesHandleEvent);

		else if (formId == DisplayDialog)
			FrmSetEventHandler (frm, DisplayOptionsHandleEvent);
		
		FtrSet (sysFileCDatebook, recentFormFeature,
					formId == AgendaView ? AgendaView : DayView);

		return (true);
		}

	return (false);
}


/***********************************************************************
 *
 * FUNCTION:    PreprocessEvent
 *
 * DESCRIPTION: This routine handles special event processing that
 *              needs to occur before the System Event Handler get 
 *              and event.
 *
 * PARAMETERS:  event  - a pointer to an EventType structure
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	1/10/97	Initial Revision
 *			CSS	06/22/99	Standardized keyDownEvent handling
 *								(TxtCharIsHardKey, commandKeyMask, etc.)
 *
 ***********************************************************************/
static void PreprocessEvent (EventType* event)
{

	// We want to allow the datebook event handled see the command keys
	// before the any other event handler get them.  Some of the databook
	// views display UI that dispappears automaticial (the time in the 
	// title, or an event's descripition in the week view).  This UI
	// needs to be dismissed before the System Event Handler or the 
	// Menu Event Handler displays any UI objects.  
	if (event->eType == keyDownEvent) 
		{
		if	(	(!TxtCharIsHardKey(	event->data.keyDown.modifiers,
											event->data.keyDown.chr))
			&&	(EvtKeydownIsVirtual(event))
			&&	(event->data.keyDown.chr != vchrPageUp)
			&&	(event->data.keyDown.chr != vchrPageDown)
			&&	(event->data.keyDown.chr != vchrSendData))
			{
			FrmDispatchEvent (event);
			}
		}
}


/***********************************************************************
 *
 * FUNCTION:    EventLoop
 *
 * DESCRIPTION: This routine is the event loop for the Datebook
 *              aplication.  
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			art	6/12/95	Initial Revision
 *			grant 2/2/99	Use TimeToWait() for time to wait for next event
 *
 ***********************************************************************/
static void EventLoop (void)
{
	UInt16 error;
	EventType event;

	do
		{
		EvtGetEvent (&event, TimeToWait());
		
		PreprocessEvent (&event);
		
		if (! SysHandleEvent (&event))
			
			if (! MenuHandleEvent (NULL, &event, &error))
				
				if (! ApplicationHandleEvent (&event))
		
					FrmDispatchEvent (&event); 

//		#if	EMULATION_LEVEL != EMULATION_NONE
//		ECApptDBValidate (ApptDB);
//		#endif
		}
	while (event.eType != appStopEvent);
}

⌨️ 快捷键说明

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