/*******************************************************************
 Copyright © 1995 - 1998, 3Com Corporation or its subsidiaries ("3Com").  
 All rights reserved.
   
 This software may be copied and used solely for developing products for 
 the Palm Computing platform and for archival and backup purposes.  Except 
 for the foregoing, no part of this software may be reproduced or transmitted 
 in any form or by any means or used to make any derivative work (such as 
 translation, transformation or adaptation) without express written consent 
 from 3Com.

 3Com reserves the right to revise this software and to make changes in content 
 from time to time without obligation on the part of 3Com to provide notification 
 of such revision or changes.  
 3COM MAKES NO REPRESENTATIONS OR WARRANTIES THAT THE SOFTWARE IS FREE OF ERRORS 
 OR THAT THE SOFTWARE IS SUITABLE FOR YOUR USE.  THE SOFTWARE IS PROVIDED ON AN 
 "AS IS" BASIS.  3COM MAKES NO WARRANTIES, TERMS OR CONDITIONS, EXPRESS OR IMPLIED, 
 EITHER IN FACT OR BY OPERATION OF LAW, STATUTORY OR OTHERWISE, INCLUDING WARRANTIES, 
 TERMS, OR CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND 
 SATISFACTORY QUALITY.

 TO THE FULL EXTENT ALLOWED BY LAW, 3COM ALSO EXCLUDES FOR ITSELF AND ITS SUPPLIERS 
 ANY LIABILITY, WHETHER BASED IN CONTRACT OR TORT (INCLUDING NEGLIGENCE), FOR 
 DIRECT, INCIDENTAL, CONSEQUENTIAL, INDIRECT, SPECIAL, OR PUNITIVE DAMAGES OF 
 ANY KIND, OR FOR LOSS OF REVENUE OR PROFITS, LOSS OF BUSINESS, LOSS OF INFORMATION 
 OR DATA, OR OTHER FINANCIAL LOSS ARISING OUT OF OR IN CONNECTION WITH THIS SOFTWARE, 
 EVEN IF 3COM HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

 3Com, HotSync, Palm Computing, and Graffiti are registered trademarks, and 
 Palm III and Palm OS are trademarks of 3Com Corporation or its subsidiaries.

 IF THIS SOFTWARE IS PROVIDED ON A COMPACT DISK, THE OTHER SOFTWARE AND 
 DOCUMENTATION ON THE COMPACT DISK ARE SUBJECT TO THE LICENSE AGREEMENT 
 ACCOMPANYING THE COMPACT DISK.

 *-------------------------------------------------------------------
 * FileName:
 *		SysEvtPrv.h
 *
 * Description:
 *		Private Header for the System Event Manager
 *
 * History:
 *   	8/10/95  RM - Created by Ron Marianetti
 *
 *******************************************************************/

#ifdef	NON_PORTABLE
#ifndef __SYSEVTPRV_H__
#define __SYSEVTPRV_H__




/************************************************************
 * Structure of a Pen Capture Queue
 *
 * This structure is used to hold one or more pen strokes
 *   and is filled by the digitizer interrupt routine and emptied
 *   by application level code.
 *
 * A default size queue is allocated by the system and used to capture
 *   strokes for subsequent processing by the Graffiti recognizer
 *   or the hard icon recognizer. This queue pointer is stored in
 *   the System Event Manager Globals.
 *
 * Optionally, applications can replace the system pen queue with
 *   one of their own if it they need to hold larger strokes
 *   or more of them.
 *   
 *
 * Stroke data is stored in compressed form in this queue - refer
 *  to the comments on the routine EvtEnqueuPenPoint  for the format
 *  of the queue data.
 *************************************************************/
typedef struct PenQueueType {
	Int			start;							// start byte offset
	Int			end;								// end byte offset
	Int			size;								// size of queue in bytes
	
	UInt			strokeCount;					// # of complete strokes currently in pen queue
	Boolean		returnedPenDown;				// set after we return a pen-down event for 
														// the next stroke in the queue. Cleared after
														// we return the pen-up for the stroke.

	PointType	addLast;							// last point captured
	Int			addStrokeStart;				// offset in queue to start of stroke
														// currently being added to queue
														// -1  : no stroke being captured
	
	
	UInt			strokesRemoved;				// running count: # of strokes removed from queue.
	UInt			strokesAdded;					// running count: # of strokes added to queue.

	Int			rmvStrokeStage;				// -1  : not started
														//  0  : returned stroke info
														//  1  : returned start point
														
	PointType	rmvLast;							// last point dequeued
	PointType 	rmvStartPt;						// copy of start point of stroke currently
														//  being removed.
	
	Byte			data[1];							// 'size' bytes of data
	} PenQueueType;
typedef PenQueueType*	PenQueuePtr;



/************************************************************
 * Structure of the Key Queue
 *
 * This structure is used to hold one or more keystrokes 
 *   and is filled by numerous places including the low level
 *	  hardware key interrupt routine, the Graffiti recognizer, and
 *	  the digitizer buttons recognizer.
 *
 * A default size queue is allocated by the system. 
 *		This queue pointer is stored in the System Event Manager globals.
 *
 * Optionally, applications can replace the system key queue with
 *   one of their own if it they need to hold more keys in the queue
 *	  at one time. This may be necessary when processing large macro
 *	  strings from Graffiti.
 *
 * Key data is stored in compressed form in this queue. Refer to
 *  the comments for the function EvtEnqueueKeyString for the format
 *  of the compressed data.
 *   
 *************************************************************/
typedef struct KeyQueueType {
	UInt		start;							// start byte offset
	UInt		end;								// end byte offset
	UInt		size;								// size of queue in bytes
	
	Byte		data[1];							// 'size' bytes of data
	} KeyQueueType;
typedef KeyQueueType*	KeyQueuePtr;





/************************************************************
 * Pen button info structure. This structure is used
 *  to hold the bounds of each button on the silk screen and
 *  the ascii code and modifiers byte that each will generate.
 *************************************************************/
typedef struct PenBtnInfoType {
	RectangleType	boundsR;						// bounding rectangle of button
	UInt				asciiCode;					// ascii code for key event
	UInt				keyCode;						// virtual key code for key event
	UInt				modifiers;					// modifiers for key event
	} PenBtnInfoType;
typedef PenBtnInfoType* PenBtnInfoPtr;
	
	
	

/************************************************************
 * Key constants
 *************************************************************/
#define 	evtKeyStringEscape 	0x01		// Escape byte for encoded key strings
													// passed to EvtEnqueueKeyString or stored
													//  in key queue.


#define	evtDefaultPenQSize	0x100
#define	evtDefaultKeyQSize	0x40

#define	evtEffectiveKeyQStorage	(evtDefaultKeyQSize - sizeof(KeyQueueType))


// gremlinsFlags
#define	grmGremlinsOn			0x01
#define  grmEventTraceOn		0x02
#define	grmGremlinsIdle		0x04

/************************************************************
 * Structure of System Event Manager Globals
 *************************************************************/
typedef struct SysEvtMgrGlobalsType {
	Boolean			sendNullEvent;				// set by EvtWakeup 		
	Boolean			enableGraffiti;			// If true, enable Graffiti translation
	Boolean			enableSoftKeys;			// If true, enable digitizer button translation 
												
												
	Boolean			removeTopStroke;			// if true, remove top stroke from queue
														//  next time EvtGetSysEvent is called;
	PenQueuePtr		penQP;						// pointer to current pen queue
	UInt				penQStrokesRemoved;		// saved value of penQP->strokesRemoved. Used to
														// determine if app removed stroke from penUp
														// event or not.
														
	KeyQueuePtr		keyQP;						// pointer to current key queue
	
	RectangleType	writingR;					// enclosing rect for writing area
	UInt				appAreaBottom;				// bottom coordinate of application area.
	
	UInt				penX;							// current pen location and state
	UInt				penY;				
	Boolean			penDown;
	Boolean			displayingBatteryAlert; // to avoid re-entering battery dialog
	
	UInt				lastPenX;					// last pen location and state
	UInt				lastPenY;
	Boolean			lastPenDown;
	
	// This boolean is set by the Remote Screen Driver timer procedure periodically
	//  to force the event manager to call ScrSendUpdateArea which will send the update
	//  area of the screen to the host.
	Boolean			needRemoteScrUpdate;		// If true, call ScrSendUpdateArea 
	
	
	Byte				gremlinsFlags;				// flag to indicate if gremlins is running and
														// if we'er doing an event trace.

	Boolean			idle;
															
	} SysEvtMgrGlobalsType;
	
typedef SysEvtMgrGlobalsType* SysEvtMgrGlobalsPtr;



/************************************************************
 * System Event Manager procedures
 *************************************************************/
#ifdef __cplusplus
extern "C" {  
#endif



// Return pointer to the pen based button list
PenBtnInfoPtr	EvtGetPenBtnList(UIntPtr numButtons)
						SYS_TRAP(sysTrapEvtGetPenBtnList);
						

#ifdef __cplusplus
}
#endif


#endif //__SYSEVTPRV_H__

#endif // NON_PORTABLE

