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

#include <z_htips.hpp>
#include <z_string.hpp>
#define ZAF_HELP_TIPS_INFO
#include "gbl_def.cpp"

// ----- ZafHelpTips --------------------------------------------------------

ZafHelpTips::ZafHelpTips(ZafDeviceState state, ZafHelpTipsType tHelpTipsType) :
	ZafDevice(E_HELPTIPS, state),
	quickTipVisible(false), allowQuickSiblingDisplay(false), 
	helpTipsType(tHelpTipsType), replaceText(ZAF_NULLP(ZafIChar)),
	userPalette(ZAF_NULLP(ZafPaletteStruct))
{
	// Set the class information.
	SetStringID(className);
	SetNumberID((ZafNumberID)classID);

	// Initialize the tool tips information.
	lastMousePosition.column = lastMousePosition.line = 0;
	quickTipRegion.left = quickTipRegion.top =
		quickTipRegion.right = quickTipRegion.bottom = 0;
#if defined(ZAF_MSWINDOWS)
	displayTimerHandle = 0;
	hwnd = 0;
#elif defined(ZAF_MOTIF)
	quickTipWindow = 0;
	displayTimerHandle = 0;
	lastTime = 0;
#elif defined(ZAF_INDEPENDENT)
	displayTimerHandle = ZAF_NULLP(ZafTimer);
#elif defined(ZAF_MACINTOSH)
	displayTimer = ZAF_NULLP(ZafTimer);
	displayTimerHandle.tmAddr = ZAF_NULLH(TimerUPP);
	displayTimerHandle.tmWakeUp = displayTimerHandle.tmReserved = 0L;
	quickTipWindow = 0;
#endif
}

ZafHelpTips::~ZafHelpTips(void)
{
	// Clean up the help tip members.
	if (replaceText)
		delete []replaceText;

#if defined(ZAF_MOTIF)
	if (quickTipWindow)
		XDestroyWindow(((ZafScreenDisplay *)display)->xDisplay, quickTipWindow);
#endif
}

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

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

void ZafHelpTips::SetHelpObject(ZafWindowObject *newHelpObject)
{
	// Check for a new help object.
	// Check the window manager for updated help objects.
	if (zafWindowManager && newHelpObject != zafWindowManager->helpObject)
	{
		// Update the help object information.
		if (newHelpObject)
		{
			// If replaceText, it means that the current helpObject contains
			// helpTip information.  Restore it before replacing it as the
			// helpObject.
			if (replaceText)
			{
				zafWindowManager->SetText(replaceText);
				delete []replaceText;
			}
			const ZafIChar *text = newHelpObject->Text();
			replaceText = text ? strdup(text) : ZAF_NULLP(ZafIChar);
		}
		zafWindowManager->helpObject = newHelpObject;
	}
}

ZafHelpTipsType ZafHelpTips::SetHelpTipsType(ZafHelpTipsType tHelpTipsType)
{
	helpTipsType = tHelpTipsType;
	return (helpTipsType);
}

int ZafHelpTips::SetInitialDelay(int newInitialDelay)
{
	// Make sure the attribute has changed.
	if (initialDelay != newInitialDelay)
		initialDelay = newInitialDelay;

	// Return the current attribute.
	return (initialDelay);
}

int ZafHelpTips::SetNewHelpTipDelay(int newNewHelpTipDelay)
{
	// Make sure the attribute has changed.
	if (newHelpTipDelay != newNewHelpTipDelay)
		newHelpTipDelay = newNewHelpTipDelay;

	// Return the current attribute.
	return (newHelpTipDelay);
}

void ZafHelpTips::SetUserPalette(ZafPaletteStruct *newUserPalette)
{
	userPalette = newUserPalette;
}
