/*	XMessages.h
 *
 *		Events that are sent by the YAAF library. This is a clearing
 *	house for all library events
 */

/*  YAAF - Yet another application framework
 *  Copyright (C) 1997, 1998 William Edward Woody
 *  
 *  This library is free software; you can redistribute it
 *  and/or modify it under the terms of the GNU Library
 *  General Public License as published by the Free Software
 *  Foundation; either version 2 of the License, or any
 *  later version.
 *  
 *  This library is distributed in the hope that it will be
 *  useful, but WITHOUT ANY WARRANTY; without even the implied
 *  warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
 *  PURPOSE. See the GNU Library General Public License for
 *  more details.
 *  
 *  You should have received a copy of the GNU Library General
 *  Public License along with this library; if not, write to the
 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA 02111-1307, USA.
 *  
 *  To contact the author, either e-mail me at woody@pandawave.com, 
 *	or write to
 *  
 *          William Edward Woody
 *          In Phase Consulting
 *          1545 Ard Eevin Avenue
 *          Glendale, CA 91202
 *
 *	Or visit us on the web at http://www.pandawave.com
 */

#ifndef PandaWave_XMESSAGES
#define PandaWave_XMESSAGES

#include <XConfig.h>

/************************************************************************/
/*																		*/
/*	Forwards															*/
/*																		*/
/************************************************************************/

class XGWindow;
class XGDocument;
class XGView;
class XGSlider;
class XGInlineEdit;

/************************************************************************/
/*																		*/
/*	Application Events													*/
/*																		*/
/************************************************************************/

/*	KXGAppPreEvent
 *	KXGAppPostEvent
 *	KXGAppPeriodic
 *
 *		These are periodic events that are sent. The reason why I send
 *	three different periodic events is to allow code to be hooked in at
 *	different stages of the event loop.
 *
 *		Args:
 *
 *			arg			0
 *			parg		NULL
 */

#define KXGAppPreEvent		'pree'
#define KXGAppPostEvent		'post'
#define KXGAppPeriodic		'peri'

/*	KXGAppEvent
 *
 *		This is sent before an event is processed. This broadcasts
 *	the message structure. Return 1 if the message should not be
 *	handled by my internal event loop, return 0 (or -1) if the
 *	message should be handled
 *
 *		Arguments:
 *			arg			0
 *			parg		pointer to OS dependant event record
 */

#define KXGAppEvent			'even'

/*	KXGKeyEvent
 *
 *		Keyboard event.
 *
 *		Arguments:
 *			arg			hi word: modifier flags
 *						lo word: keyboard key code
 *			parg		NULL
 */

#define KXGKeyEvent			'keye'

#define	KKeyUpCursor		128
#define KKeyDownCursor		129
#define KKeyLeftCursor		130
#define KKeyRightCursor		131
#define KKeyInsert			132
#define KKeyDelete			133
#define KKeyHome			134
#define KKeyEnd				135
#define KKeyPageUp			136
#define KKeyPageDown		137
#define KKeyEscape			138
#define KKeyHelp			139
#define KKeyNumLock			140
#define KKeyClear			141

#define KKeyF1				160
#define KKeyF2				161
#define KKeyF3				162
#define KKeyF4				163
#define KKeyF5				164
#define KKeyF6				165
#define KKeyF7				166
#define KKeyF8				167
#define KKeyF9				168
#define KKeyF10				169
#define KKeyF11				170
#define KKeyF12				171
#define KKeyF13				172
#define KKeyF14				173
#define KKeyF15				174

/*	KXGMenuKey
 *
 *		This is sent when a menu key (a key with an accelerator)
 *	is sent. This is used by Windows and X for keyboard navigation of
 *	dialog boxes
 *
 *		Arguments:
 *			arg			hi word: modifier flags
 *						lo word: keyboard key code
 *			parg		NULL
 */

#define KXGMenuKey			'keym'

#if OPT_WINOS

/*	KXGWInternal
 *
 *		Internal event; this is sent to the view that contains a 
 *	control, so that control events can be funneled through the YAAF
 *	event dispatch mechanism.
 *
 *		This is specific to Windows 95/Windows NT
 */

#define KXGWInternal			'wint'

struct XGSWInternalRecord {
	HWND		w;
	UINT		msg;
	WPARAM		wp;
	LPARAM		lp;
};

#endif // OPT_WINOS

/************************************************************************/
/*																		*/
/*	Menu Events															*/
/*																		*/
/************************************************************************/

/*	KXGCurMenuBar
 *
 *		This is sent to the current focus to determine the menu
 *	bar that should be displayed with this window.
 *
 *		Arguments:
 *			arg				0
 *			parg			NULL
 *
 *		Returns:
 *			0				Do not change the current menu bar
 *			-1				(Default in XGDispatch--sends up)
 *			N > 0			The menu bar resource to show
 */

#define KXGCurMenuBar			'mbar'

/*	KXGGetMenuStatus
 *
 *		This gets the status of this menu item in the menu bar. This
 *	message is dispatched to the current focus of this focus event
 *	for every menu command when the XGMenu::UpdateMenuBar() method
 *	is called. This is used to determine which items should be checked
 *	and which should be enabled.
 *
 *		A toolbar which provides menu command functionality can also
 *	send this command in order to determine which buttons in the toolbar
 *	should be activated and which should be hilited.
 *
 *		Parameters:
 *
 *				arg				Command ID
 *				parg			Pointer to XGSMenuStatus record
 *
 *	NOTE: The handler which is processing this event should return
 *	'-1' if this menu command is not handled here, and 0 if it is.
 */

#define KXGGetMenuStatus			'stat'

/*	XGSMenuStatus
 *
 *		This is the record passed as part of the KXGGetMenuStatus
 *	event; this contains the place where the return results should
 *	be placed.
 */

struct XGSMenuStatus {
	bool		enable;				// should this be enabled?
	bool		check;				// should this be checked?
	char		mark;				// mark to use for menu check
};

/*
 *	XGSMenuStatus.mark constants
 */

#define KXGCommand			0x11	// Use command mark
#define KXGCheckmark		0x12	// Use checkmark (default)
#define KXGDiamond			0x13	// Use diamond

/*	KXGDoMenuCommand
 *
 *		This gets sent when the specified menu command was clicked
 *	by the user. This event is dispatched as a result of calling the
 *	OS dependant event processing routines for the menu bar with the
 *	specified focus.
 *
 *		A toolbar which provided menu command functionality can
 *	also send this event when a button in the toolbar is pressed
 *
 *		Parameters:
 *
 *				arg				Command ID
 *				parg			Undefined; set to NULL
 *
 *	NOTE: The handler which is processing this event should return
 *	'-1' if this command is not handled here, and 0 if it is.
 */

#define KXGDoMenuCommand			'menu'

/************************************************************************/
/*																		*/
/*	File Events															*/
/*																		*/
/************************************************************************/

/*	KXGOpenApplication
 *
 *		open application. Sent if no files are explicitly specified
 *
 *		Parameters:
 *
 *				arg				0
 *				parg			Undefined; set to NULL
 */

#define KXGOpenApplication			'oapp'

/*	KXGOpenDocument
 *
 *		Open document. Sent when a document is specified in the command
 *	line/ on application launch
 *
 *		Parameters:
 *
 *				arg				0
 *				parg			Pointer to file specification.
 *								(Macintosh: FSSpec *)
 *								(Windows, X: char *)
 */

#define KXGOpenDocument				'odoc'

/*	KXGPrintDocument
 *
 *		Print document. Sent when the document is asked to be printed
 *
 *		Parameters:
 *
 *				arg				0
 *				parg			Undefined; set to NULL
 */

#define KXGPrintDocument			'pdoc'

/*	KXGQuitApplication
 *
 *		Quit application
 *
 *		Parameters:
 *
 *				arg				0
 *				parg			Undefined; set to NULL
 */

#define KXGQuitApplication			'qapp'


/************************************************************************/
/*																		*/
/*	Document Events														*/
/*																		*/
/************************************************************************/

/*	KXGEventDocRenamed
 *
 *		The document specified was renamed. This is sent by the document
 *	to all receivers registered with that document
 *
 *		Arguments:
 *			long arg		0
 *			void *parg		pointer to XGSDocEvent record
 */

#define KXGEventDocRenamed			'docr'

struct XGSDocEvent {
	XGDocument						*doc;
};

/*	KXGEventDocChanged
 *
 *		Sent when the contents of the document have been changed.
 *	All doc events use the same parameters
 */

#define KXGEventDocChanged			'docc'

/*	KXGEventDocSaved
 *
 *		The document specified was successfully saved
 */

#define KXGEventDocSaved			'docs'

/************************************************************************/
/*																		*/
/*	Window Events														*/
/*																		*/
/************************************************************************/

/*	KXGEventWindowName						(dispatch)
 *
 *		This event is sent upwards when a window is renamed. This gives
 *	the objects above which are maintaining a window menu to update it's
 *	contents
 *
 *		Arguments:
 *			long arg		0
 *			void *parg		pointer to XGWindow class (window already renamed)
 */

#define KXGEventWindowName			'namw'

/*	XGSWindowEvent
 *
 *		This is the way views are passed through the parg pointer.
 *	Instead of a pointer to the parg (which can be confusing), we
 *	pass a pointer to one of these.
 */

struct XGSWindowEvent {
	XGWindow						*window;
};

/*	KXGEventWindowCreate						(dispatch)
 *
 *		This event is sent when a window is created
 *
 *		Arguments:
 *			long arg		0
 *			void *parg		pointer to XGWindow class (window already created)
 *
 *		NOTE: 
 *			return values:	If the window is not to be created, throw error
 */

#define KXGEventWindowCreate		'crew'

/*	KXGEventWindowPreDestroy					(dispatch)
 *
 *		This event is sent when a window is about to be destroyed
 *
 *		Arguments:
 *			long arg		0
 *			void *parg		pointer to XGWindow class (window not yet destroyed)
 *
 *		NOTE: 
 *			return values:	If the window is not to be destroyed, throw error
 */
 
#define KXGEventWindowPreDestroy 	'pdsw'

/*	KXGEventWindowDestroy						(dispatch)
 *
 *		This event is sent when the window is destroyed
 *
 *		Arguments:
 *			long arg		0
 *			void *parg		pointer to XGWindow class (window not yet destroyed)
 */

#define KXGEventWindowDestroy		'desw'

/*	KXGEventWindowDirty
 *
 *		This message is sent by the window when there is no document
 *	associated with this window. this gives the form and the app the
 *	opportunity to complain that a window is dirty, even though it
 *	contains no document
 */

#define KXGEventWindowDirty			'badw'

/*	KXGEventWindowSave
 *
 *		This is sent by the window when there is no document and the
 *	window should be saved.
 */

#define KXGEventWindowSave			'savw'

/************************************************************************/
/*																		*/
/*	Control Events														*/
/*																		*/
/************************************************************************/

/*	KXGControlClick
 *
 *		The control specified was clicked on. This is sent by buttons
 *	and other things that may be triggered
 *
 *		Args:
 *
 *			arg			ID of the control sending this message
 *			parg		NULL
 */

#define	KXGControlClick				'cclk'

/*	KXGKeyClick
 *
 *		This is sent by the edit box every time a key is pressed. this
 *	gives the top level code the opportunity to say 'no' to this key
 *
 *		Args:
 *
 *			arg			ID of the control sending this message
 *			parg		pointer to resulting edit string (c string)
 */

#define KXGKeyClick					'kclk'

/*	KXGListSelect
 *
 *		This message is sent when the list is double-clicked on
 *
 *		Args:
 *
 *			arg			ID of the control sending this message
 *			parg		NULL
 */
 
#define KXGListSelect				'lsel'

/*	KXGListValue
 *
 *		This message is sent when the list has had a state change
 *	due to being clicked on
 *
 *		Args:
 *
 *			arg			ID of the control sending this message
 *			parg		NULL
 */
 
#define KXGListValue				'lval'

/*	KXGPopValue
 *
 *		Popup value
 *
 *		Args:
 *
 *			arg			ID of the control sending this message
 *			parg		NULL
 */

#define	KXGPopValue					'pval'

/*	KXGSliderStart
 *
 *		This message is sent <<before>> the control's values are
 *	changed. This gives anything which relies on the control's
 *	value to update an opportunity to do so before change messages
 *	are sent.
 *
 *		Args:
 *
 *			arg			ID of the control sending this message
 *			parg		NULL
 */

#define KXGSliderStart				'scrs'

/*	KXGSliderValue
 *
 *		This message is sent by controls which automatically change
 *	in value, such as sliders and scrollbars
 *
 *		Args:
 *
 *			arg			ID of the control sending this message
 *			parg		Pointer to XGSValue record
 */

#define KXGSliderValue				'sval'

struct XGSValue {
	XGSlider						*slider;
	long							oldVal;
	long							newVal;
};

/*	KXGInlineClose
 *
 *		Inline edit view will close. If this returns 1, the
 *	inline edit view won't be closed.
 *
 *		Args:
 *
 *			arg			inline edit refnum
 *			parg		Pointer to XGSInline
 */

#define KXGInlineClose				'icls'

struct XGSInline {
	XGInlineEdit					*edit;
};


#endif
