/*	XForm.h
 *
 *		This is the code template for the 'form' handler; this is the
 *	message handling and control layer which nominally coordinates the
 *	behaviour of a window.
 */

/**********************************************************************

  YAAF is Copyright 1997-1999 by William Woody.

  Redistribution and use in source and binary forms, with or without 
  modification, are permitted provided that the following conditions 
  are met:

  Redistributions of source code must retain the above copyright notice, 
  this list of conditions and the following disclaimer.

  Neither the name of the copyright holder or other contributors may
  be used to promote products derived from this software without
  specific written prior permission.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
  SOFTWARE.
  
  Contact:   woody@alumni.caltech.edu
  Web page:  http://www.pandawave.com/yaaf/

**********************************************************************/

#ifndef PandaWave_XFORM
#define PandaWave_XFORM

#include <XConfig.h>
#include <XEvent.h>
#include <XDocument.h>

/**@name Form Management
 *
 *		These are the form management classes.
 *
 *		The basic idea is that to build a YAAF application, you create
 *	custom controls using the XGView class which handle the contents of
 *	your windows, and you associate an XGForm object with each window
 *	in order to tie those controls together. (Of course you could do
 *	this at the XGWindow level, but this gives you another option.)
 */
 
//@{

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

class XGWindow;
class XGDocument;
struct XGSWindowInitRecord;

/************************************************************************/
/*																		*/
/*	Form manager template												*/
/*																		*/
/************************************************************************/

/*$	XGForm
 *
 *		This is the 'form' class; this is an abstract class which provides
 *	the callbacks for managing a window.
 *
 *		The idea here is that a window is contructed out of a collection
 *	of self-contained views; these views are then controlled by the
 *	form belonging to that window. The forms themselves insert between
 *	the document and the window, and control the contents of the
 *	views in that window from the contents of the document.
 *
 *		How that works varies, depending on the view. A view can be
 *	rather promiscuous and actually get into the hands of the document
 *	database, though this is highly unusual. In most cases, the form
 *	mediates the communications between the document and the window,
 *	by reading the document database and entering the information into
 *	the window views.
 */

class XGForm : public XGDispatch {
	public:
								XGForm();
		virtual					~XGForm();
		
		void					AttachWindow(short resID);
		void					AttachWindow(XGWindow *);

		/*
		 *	Form specific messages
		 */
		
		virtual void			DoFormInitialize();
		virtual void			DoFormTerminate();
		
		/*
		 *	Window processing messages
		 */
		
		virtual void			DoPreCreateWindow(XGSWindowInitRecord *);
		virtual bool			DoQueryDestroyWindow();
		
		/*
		 *	Content access
		 */

		XGWindow				*GetWindow()
									{
										return fWindow;
									}
		/*
		 *	Event placeholder
		 */
		
		DECLAREDISPATCH
	protected:
		XGDispatch				*GetParentDispatch();
	private:
		XGWindow				*fWindow;
	
	friend class XGWindow;
};

/*$	XGDocForm
 *
 *		This is a form object which provides basic document handling
 *	capabilities.
 */

class XGDocForm : public XGForm {
	public:
								XGDocForm(bool secondary = false);
		virtual					~XGDocForm();

		/*
		 *	Warn to close this window functionality
		 */
		
		void					AttachDocument(XGDocument *);
		void					DetachDocument();

		/*
		 *	Event overrides
		 */
		
		virtual bool			DoQueryDestroyWindow();

		/*
		 *	Events
		 */
		
		virtual void			DoDocumentChanged();
		virtual void			DoDocumentRenamed();
		virtual void			DoDocumentRevert();
		virtual void			DoDocumentSaved();
		
		/*
		 *	Content access
		 */

		XGDocument				*GetDocument()
									{
										return fDocument;
									}
		/*
		 *	Messages
		 */

		DECLAREDISPATCH
	
	protected:
		XGDispatch				*GetParentDispatch();
		
	private:
		bool					fSecondary;
		XGDocument				*fDocument;
		XGDocForm				*fNext;

	friend class XGDocument;
};

//@}

#endif // PandaWave_XFORM
