//	Zinc Application Framework - Z_DLGWIN.CPP
//	COPYRIGHT (C) 1990-1999.  All Rights Reserved.
//	Zinc Software Incorporated.  Pleasant Grove, Utah  USA

#include <z_dlgwin.hpp>

#if defined(ZAF_LOCAL_FILE_STATICS)
#define ZAF_DIALOG_WINDOW_INFO
#include "gbl_def.cpp"
#else
#include <z_dlgall.hpp>
#define ZAF_LOCAL_FILE_STATICS
#define ZAF_DIALOG_WINDOW_INFO
#define ZAF_ERROR_STUB_INFO
#define ZAF_ERROR_SYSTEM_INFO
#define ZAF_FILE_DIALOG_INFO
#define ZAF_HELP_STUB_INFO
#define ZAF_HELP_SYSTEM_INFO
#define ZAF_MDI_WINDOW_INFO
#define ZAF_MESSAGE_WINDOW_INFO
#define ZAF_SCROLLED_WINDOW_INFO
#include "gbl_def.cpp"
#endif

// ----- ZafDialogWindow ----------------------------------------------------

ZafDialogWindow::ZafDialogWindow(int left, int top, int width, int height) :
	ZafWindow(left, top, width, height)
{
	SetDestroyable(false);
	SetModal(true);
	SetSizeable(false);
}

ZafDialogWindow::ZafDialogWindow(const ZafDialogWindow &copy) :
	ZafWindow(copy)
{
}

ZafDialogWindow::~ZafDialogWindow(void)
{
}

ZafEventType ZafDialogWindow::Control(ZafQFlags flags)
{
	// Dialog must not be destroyed within the control loop.
	if (destroyable)
		return (S_ERROR);

	// Add the object to the window manager.
	zafWindowManager->Add(this);

	// Wait for user response.
	ZafEventType ccode = S_NO_OBJECT;
	ZafEventStruct event;
	do
	{
		if (zafEventManager->Get(event, flags) == 0)
		{
			if (event.type >= S_DIALOG_FIRST && event.type <= S_DIALOG_LAST)
				ccode = Event(event);
			else
				windowManager->Event(event);
		}
	} while (screenID && ccode == S_NO_OBJECT && event.type != S_EXIT);

 	// Remove the object from the window manager.
	zafWindowManager->Subtract(this);

	// Return the control code.
	return (ccode);
}

ZafWindowObject *ZafDialogWindow::Duplicate(void)
{
	return (new ZafDialogWindow(*this));
}

ZafEventType ZafDialogWindow::Event(const ZafEventStruct &event)
{
	// Check for zinc events.
	ZafEventType ccode = event.type;
	switch (ccode)
	{
	case S_DLG_OK:
	case S_DLG_YES:
	case S_DLG_NO:
	case S_DLG_ABORT:
	case S_DLG_RETRY:
	case S_DLG_IGNORE:
	case S_DLG_CANCEL:
		break;

	default:
		ccode = ZafWindow::Event(event);
		break;
	}

	// Return the control code.
	return (ccode);
}

bool ZafDialogWindow::IsA(ZafClassID compareID) const
{
	return ((compareID == classID) ? true : ZafWindow::IsA(compareID));
}

bool ZafDialogWindow::IsA(ZafClassName compareName) const
{
	return (!strcmp(compareName, className) ? true : ZafWindow::IsA(compareName));
}

bool ZafDialogWindow::SetAcceptDrop(bool )
{
	// acceptDrop is false for this class.
	acceptDrop = false;
	return (acceptDrop);
}

bool ZafDialogWindow::SetBordered(bool )
{
	// bordered is false for this class.
	bordered = false;
	return (bordered);
}

bool ZafDialogWindow::SetDisabled(bool )
{
	// disabled is false for this class.
	disabled = false;
	return (disabled);
}

bool ZafDialogWindow::SetNoncurrent(bool )
{
	// noncurrent is false for this class.
	noncurrent = false;
	return (noncurrent);
}

bool ZafDialogWindow::SetParentPalette(bool )
{
	// parentPalette is false for this class.
	parentPalette = false;
	return (parentPalette);
}

ZafRegionType ZafDialogWindow::SetRegionType(ZafRegionType )
{
	// regionType is ZAF_INSIDE_REGION for this class.
	regionType = ZAF_INSIDE_REGION;
	return (regionType);
}

bool ZafDialogWindow::SetSizeable(bool )
{
	// sizeable is false for this class.
	sizeable = false;
	return (sizeable);
}

bool ZafDialogWindow::SetTemporary(bool )
{
	// temporary is false for this class.
	temporary = false;
	return (temporary);
}

// ----- Persistent functions -----------------------------------------------
#if defined(USE_ZAF_PERSISTENCE)
ZafDialogWindow::ZafDialogWindow(const ZafIChar *name, ZafObjectPersistence &persist) :
	ZafWindow(name, persist.PushLevel(className, classID, ZAF_PERSIST_ROOT_DIRECTORY))
{
	// Read the data.
	persist.PopLevel();
	if (persist.Error() != ZAF_ERROR_NONE)
		SetError(persist.Error());
}

ZafElement *ZafDialogWindow::Read(const ZafIChar *name, ZafObjectPersistence &persist)
{
	return (new ZafDialogWindow(name, persist));
}

void ZafDialogWindow::Write(ZafObjectPersistence &persist)
{
	// Write the object.
	ZafWindow::Write(persist.PushLevel(className, classID, ZAF_PERSIST_ROOT_DIRECTORY));
	persist.PopLevel();
	if (persist.Error() != ZAF_ERROR_NONE)
		SetError(persist.Error());
}
#endif
