/*	XDialogs.h
 *
 *		This contains the declarations for both the modal and the
 *	modeless dialog boxes
 */

/*  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_XDIALOGS
#define PandaWave_XDIALOGS

#include <XConfig.h>
#include <XWindow.h>

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

class XGDialog;
class XGDocument;
class XGForm;

/************************************************************************/
/*																		*/
/*	Dialog Events														*/
/*																		*/
/************************************************************************/

/*	KXGDialogMessage
 *
 *		Dialog messages. This is basically events sent by the dialog
 *	to the callback, rather than messages sent by different controls
 */

#define KXGDialogMessage	'dmsg'

#define KXGDMEndDialog		1
#define KXGDMInitDialog		2

/************************************************************************/
/*																		*/
/*	Dialog background													*/
/*																		*/
/************************************************************************/

/*	@C"XGDialogView"
 *	@H"XDialog.h"
 *	@D"XGView"
 *	@I
 *
 *		background view which sets the color of the background, and
 *	manages the contents
 */

class XGDialogView : public XGView {
	public:
								XGDialogView(XGOwner *p, XGSViewInitRecord &);
		virtual					~XGDialogView();
		
		/*
		 *	Messages
		 */
		
		void					DoDrawView(Rect);
};

/************************************************************************/
/*																		*/
/*	Modal Dialog Declarations											*/
/*																		*/
/************************************************************************/

/*
 *	Procedure callback
 */

typedef long (*XGPDialogProc)(XGDialog *,void *,long,long,void *);

/*	@C"XGDialog"
 *	@D"XGWindow"
 *	@H"XDialog.h"
 *	@I
 *
 *		This is the dialog box declaration. This declaration is set
 *	up so I can be created either modal or modeless; modal dialogs
 *	should use the modal dialog function setup given below
 */

class XGDialog : public XGWindow {
	public:
								XGDialog(XGSWindowInitRecord &, XGDocument *, XGForm *);
								XGDialog(XGArgStream &, XGDocument *, XGForm *);
		virtual					~XGDialog();
		bool					CloseWindow();
		
		enum {
			kClassID = 'dlog'
		};
		
		/*
		 *	Modeless creation/destruction
		 */
		
		static XGDialog			*Create(short,XGPDialogProc, void *);
		static XGDialog			*Create(const unsigned char *,
										XGPDialogProc, 
										void *);
		
		/*
		 *	Modal creation/destruction
		 */
		
		static long				ModalDialog(short,XGPDialogProc, void *);
		static long				ModalDialog(const unsigned char *,
											XGPDialogProc, 
											void *);
		static long				ModalAlert(short, 
										   const char *,
										   const char *, 
										   const char *, 
										   const char *);
		static long				ModalAlert(const unsigned char *, 
										   const char *, 
										   const char *, 
										   const char *, 
										   const char *);
		
		/*
		 *	End the dialog
		 */
		
		void					EndDialog(long v);
		
		/*
		 *	Message management
		 */
		
		DECLAREDISPATCH
		long					Dispatch(long,long,void *);
		long					DoKey(long,void *);
		
#if OPT_MACOS
		long					DoMenuKey(long,void *);
#endif

		/*
		 *	Contents management
		 */
		
		void					GetText(short,short,char *);
		void					SetText(short,const char *);
		long					GetValue(short);
		void					SetValue(short,long);
		
		void					SetDefaultOK(short);
		void					SetDefaultCancel(short);

	private:
		static XGDialog			*CreateInit(XGDialog *, XGPDialogProc, void *);
		static long				ModalRun(XGDialog *);
		
		static void				ModifyText(char *text, const char **list);
		static long				AlertProc(XGDialog *, void *, long, long, void *);
		long					SendMessage(long,long,void *);

		long					fTermValue;
		bool					fTerminate;
		bool					fModal;
		void					*fDataPtr;
		XGPDialogProc			fDialogProc;
		
		short					fOK;
		short					fCancel;
		
		XGDialogView			*fDialogView;
};


#endif // PandaWave_XDIALOGS
