/*	XGDocEditor.cpp
 *
 *		The basic document editor support mixin class
 */

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

  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/

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

#include <XConfig.h>			// must be first to optimize compile on MSVC++
#include <XDocument.h>
#include <XError.h>

/************************************************************************/
/*																		*/
/*	Construction/Destruction											*/
/*																		*/
/************************************************************************/

/*$	XGDocEditor::XGDocEditor
 *
 *		Construct me.
 */

XGDocEditor::XGDocEditor()
{
	fDocument = NULL;
	fNext = NULL;
}

/*$	XGDocEditor::~XGDocEditor
 *
 *		Destruct me
 */

XGDocEditor::~XGDocEditor()
{
	DetachDocument();
}

/************************************************************************/
/*																		*/
/*	Editor Event Support												*/
/*																		*/
/************************************************************************/

/*$	XGDocEditor::AttachDocument
 *
 *		Attach the specified document to me
 */

void XGDocEditor::AttachDocument(XGDocument *doc)
{
	Assert(fDocument == NULL);
	
	fDocument = doc;
	fNext = doc->fList;
	doc->fList = this;
	
	DoDocumentInitialize();
}

/*$	XGDocEditor::DetachDocument
 *
 *		Detach this document
 */

void XGDocEditor::DetachDocument()
{
	XGDocEditor *foo;
	
	Assert(fDocument != NULL);			// make sure things are called right
	
	DoDocumentTerminate();				// send terminate message
	
	if (fDocument->fList == this) {		// remove me from the document list
		fDocument->fList = fNext;
	} else {
		foo = fDocument->fList;
		while (foo != NULL) {
			if (foo->fNext == this) {
				foo->fNext = fNext;
				break;
			}
			foo = foo->fNext;
		}
	}

	fDocument = NULL;					// and clear the document flag
}

/************************************************************************/
/*																		*/
/*	Empty messages														*/
/*																		*/
/************************************************************************/

/*$	XGDocEditor::DoDocumentInitialize
 *
 *		Default initialization routine, called when the document is
 *	attached to this editor object
 */

void XGDocEditor::DoDocumentInitialize()
{
}

/*$	XGDocEditor::DoDocumentTerminate
 *
 *		Default terminate routines, called when the document is
 *	detached from this document. This may not get called if this
 *	editor is destroyed first.
 */

void XGDocEditor::DoDocumentTerminate()
{
}

/*$	XGDocEditor::DoDocumentChanged
 *
 *		Default document changed routine; does nothing
 */

void XGDocEditor::DoDocumentChanged()
{
}

/*$	XGDocEditor::DoDocumentRenamed
 *
 *		Default renamed routine; does nothing if the document is renamed
 */

void XGDocEditor::DoDocumentRenamed()
{
}

/*$	XGDocEditor::DoDocumentRevert
 *
 *		Default revert routine; this does nothing if the project is reverted
 */

void XGDocEditor::DoDocumentRevert()
{
}

/*$	XGDocEditor::DoDocumentSaved
 *
 *		Default saved routine; does nothing if this document is saved
 */

void XGDocEditor::DoDocumentSaved()
{
}

