File:  [RetroPC.NET] / xmil / palm / support_files / PalmNavigator.h
Revision 1.1: download - view: text, annotated - select for diffs
Sat Feb 26 12:59:51 2005 JST (20 years, 8 months ago) by tk800
Branches: MAIN
CVS tags: HEAD
support Treo and T5[palm](tk800)

/******************************************************************************
 * Copyright (c) 2003 Palm, Inc. or its subsidiaries.
 * All rights reserved.
 *****************************************************************************/
 
/**
 * @file 	PalmNavigator.h
 * @version 1.0
 * @date 	02/29/2002
 *
 * Contains 5-way navigator-specific definitions.
 *
 * Five-way navigation macros and values for key states are included
 * in this file.
 *
 * <hr>
 */

#ifndef __PALMNAVIGATOR_H__
#define __PALMNAVIGATOR_H__

#include "PalmChars.h"

#define navFtrCreator           	'fway'		/**< Creator ID for 5-Way navigator. */
#define navFtrVersion           	0			/**< Feature id for 5-Way. */
#define navVersion              	0x00010000	/**< Version for 5-Way. */
 
#define keyBitNavLeft				0x01000000	/**< Key state mask to check the five way navigation LEFT button. */
#define keyBitNavRight				0x02000000	/**< Key state mask to check the five way navigation RIGHT button. */
#define keyBitNavSelect				0x04000000	/**< Key state mask to check the five way navigation SELECT button. */
#define keyBitNavLRS				0x07000000	/**< Key state mask to check the five way navigation LEFT, RIGHT and SELECT buttons. */

#define navBitUp					0x0001	/**< Key mask for the five way navigation UP button. */
#define navBitDown					0x0002	/**< Key mask for the five way navigation DOWN button. */
#define navBitLeft					0x0004	/**< Key mask for the five way navigation LEFT button. */
#define navBitRight					0x0008	/**< Key mask for the five way navigation RIGHT button. */
#define navBitSelect				0x0010	/**< Key mask for the five way navigation SELECT button. */
#define navBitsAll					0x001F	/**< Key mask for all five way navigation buttons. */

#define navChangeUp					0x0100	/**< Key mask for the five way navigation UP button state change. */
#define navChangeDown				0x0200	/**< Key mask for the five way navigation DOWN button state change. */
#define navChangeLeft				0x0400	/**< Key mask for the five way navigation LEFT button state change. */
#define navChangeRight				0x0800	/**< Key mask for the five way navigation RIGHT button state change. */
#define navChangeSelect				0x1000	/**< Key mask for the five way navigation SELECT button state change. */
#define navChangeBitsAll			0x1F00	/**< Key mask for all five way navigation buttons state change. */

/**
 * @def IsFiveWayNavEvent(eventP)
 *
 * A macro to use for apps that support navigation using the 5-way.
 * This macro will let you test whether an event was generated by the 5-way.
 * For applications that treat up and down hard buttons differently than up and
 * down on the 5-way, this macro can be used to determine which action to take
 * if NavKeyPressed returns true for Up or Down.
 * 
 * @sample
 * @code if (IsFiveWayNavEvent(eventP)) {
 *		// Handle five way events here
 * } @endcode
 */
#define IsFiveWayNavEvent(eventP)														\
(																						\
	 ((eventP)->data.keyDown.chr == vchrPageUp ||										\
	  (eventP)->data.keyDown.chr == vchrPageDown ||										\
	  (eventP)->data.keyDown.chr == vchrNavChange)										\
&&																						\
	 (((eventP)->data.keyDown.keyCode & (navBitsAll | navChangeBitsAll)) != 0)			\
)


/**
 * A macro to use for apps that support navigation using the 5-way.
 * By using this macro, we have consistent behavior in all our apps
 * when it comes to how it handles multiple simultaneous button presses.
 * 
 * @remark
 * Only act when the select button is released, and only if none of the
 * direction buttons are down (or being released) at the time, and only if the select
 * button has not been held down long enough to start repeating. By ignoring repeat
 * events for the select button, we ensure that the launcher will be run if the select
 * button is held down. By waiting until the button is released, we ensure that the
 * select action is not taken before the launcher is run.
 *
 * @sample
 * @code if (NavSelectPressed(eventP)) {
 *		// Select was pressed
 * } @endcode
 * 
 */
#define NavSelectPressed(eventP)														\
(																						\
	IsFiveWayNavEvent(eventP)															\
&&																						\
	(((eventP)->data.keyDown.modifiers & autoRepeatKeyMask) == 0)						\
&&																						\
	(((eventP)->data.keyDown.keyCode & (navBitsAll | navChangeBitsAll)) ==				\
																	 navChangeSelect)	\
)


/**
 * A macro to use for apps that support navigation using the 5-way.
 * By using this macro, we have consistent behavior in all our apps
 * when it comes to how it handles multiple simultaneous button presses.
 * You can use this macro even if the device does not have a 5-way controller.
 * 
 * @remark
 * Act only when one direction is pressed without any other direction (or select) being
 * down at the time. Repeat if the button is held down, but not if other buttons are
 * pressed.
 *
 * @sample
 * @code
 * if (NavDirectionPressed(eventP, Left))
 * if (NavDirectionPressed(eventP, Right))
 * if (NavDirectionPressed(eventP, Up))		- also works without 5-way
 * if (NavDirectionPressed(eventP, Down))	- also works without 5-way @endcode
 *
 */
#define NavDirectionPressed(eventP, nav)												\
(IsFiveWayNavEvent(eventP)																\
	? (((eventP)->data.keyDown.modifiers & autoRepeatKeyMask)							\
	 	? (((eventP)->data.keyDown.keyCode & (navBitsAll | navChangeBitsAll)) ==		\
	 				(navBit ## nav))													\
	 	: (((eventP)->data.keyDown.keyCode & (navBitsAll | navChangeBitsAll)) ==		\
					(navBit ## nav | navChange ## nav)))								\
	: (((eventP)->data.keyDown.chr == vchrPageUp && navBit ## nav == navBitUp) ||		\
	 	((eventP)->data.keyDown.chr == vchrPageDown && navBit ## nav == navBitDown))	\
)


/**
 * A macro to use for apps that support navigation using the 5-way.
 * By using this macro, we have consistent behavior in all our apps
 * when it comes to how it handles multiple simultaneous button presses.
 * You can use this macro even if the device does not have a 5-way controller.
 * 
 * @sample
 * @code
 * if (NavKeyPressed(eventP, Select))
 * if (NavKeyPressed(eventP, Left))
 * if (NavKeyPressed(eventP, Right))
 * if (NavKeyPressed(eventP, Up))		- also works without 5-way
 * if (NavKeyPressed(eventP, Down))		- also works without 5-way @endcode
 */
#define NavKeyPressed(eventP, nav)														\
((navBit ## nav == navBitSelect)														\
	? NavSelectPressed(eventP)															\
	: NavDirectionPressed(eventP, nav)													\
)

#endif // __PALMNAVIGATOR_H__

RetroPC.NET-CVS <cvs@retropc.net>