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

#include <z_error.hpp>
#include <z_help.hpp>
#if defined(ZAF_USE_GEOMETRY_MANAGER)
#	include <z_gmgr.hpp>
#endif
#include <z_icon1.hpp>
#include <z_max.hpp>
#include <z_min.hpp>
#include <z_mouse2.hpp>
#include <z_title.hpp>
#include <z_scrll2.hpp>
#include <z_sys.hpp>
#include <z_string.hpp>
#include <z_app.hpp>
#include <z_utils.hpp>
#define ZAF_HELP_SYSTEM_INFO
#include "lang_def.cpp"
#include "img_def.cpp"
#include "gbl_def.cpp"

static ZafIChar ZAF_FARDATA _topicStringID[] = ZAF_ITEXT("TOPIC_CONTEXT");
static ZafIChar _matchAll[] = ZAF_ITEXT("*");
static ZafIChar _dataName[] = ZAF_ITEXT("objectData");

// ----- ZafHelpSystem ------------------------------------------------------

ZafHelpSystem::ZafHelpSystem(ZafFileSystem *tHelpStorage) :
	ZafHelpStub(), ZafWindow(0, 0, 66, 11),
	helpStorage(tHelpStorage)
{
	// Initialize the global variable.
	if (!zafHelpSystem)
		zafHelpSystem = this;

	// Check the language and locale information.
	messages = ZafLanguageManager::Allocate(className, defaultMessages);
	ImageAllocate();

	// Center the window.
	zafWindowManager->Center(this);

	SetDestroyable(false);

#if defined(ZAF_USE_GEOMETRY_MANAGER)
	gmgr = new ZafGeometryManager;
	Add(gmgr);
#endif

	CreateIndexFields();
	CreateGeneralFields();
	CreateTopicFields();
}

ZafHelpSystem::ZafHelpSystem(const ZafHelpSystem &copy) :
	ZafHelpStub(), ZafWindow(copy),
	helpStorage(copy.helpStorage)
{
	// We need to destroy the information to ensure the fields are
	// initialized properly.
	support.Destroy();
	Destroy();

	CreateGeneralFields();
	CreateIndexFields();
	CreateTopicFields();
}

ZafHelpSystem::~ZafHelpSystem(void)
{
	// Remove and delete the support windows.
	if (windowManager)
		windowManager->Subtract(this);

	RemoveIndexFields();
	delete indexTopic;
	delete indexInstruction;
	delete indexTitle;
	delete indexContext;

	// Delete the index constraints.
	delete indexTopicConstraint;
	delete indexInstructionConstraint;
	delete indexTitleAttach;
	delete indexContextAttachRight;
	delete indexContextAttachBottom;
	delete indexContextDimension;

	RemoveTopicFields();
	delete topicTitle;
	delete topicContext;

	// Delete the topic constraints
	delete topicTitleConstraint;
	delete topicContextAttachRight;
	delete topicContextAttachBottom;
	delete topicContextDimension;

	// Free the language information.
	ZafLanguageManager::Free(messages);
	ImageFree();
}

void ZafHelpSystem::AddIndexFields(void)
{
	// Load the help contexts.
	if (helpStorage && !indexContext->First())
	{
		eventManager->SetDeviceImage(E_MOUSE, DM_WAIT);
		helpStorage->ChDir(ZafFileSystem::rootDirectoryName);
		helpStorage->ChDir(className);
		indexContext->Destroy();
		ZafFileInfoStruct fileInfo;
		for (int finished = helpStorage->FindFirst(fileInfo, _matchAll); 
			!finished; finished = helpStorage->FindNext(fileInfo, _matchAll))
		{
			ZafButton *button = new ZafButton(0, 0, 30, 1, fileInfo.stringID,
				ZAF_NULLP(ZafBitmapData), ZAF_FLAT_BUTTON);
			button->SetDepth(0);
			button->SetHelpContext(fileInfo.name);
			button->SetHzJustify(ZAF_HZ_LEFT);
			button->SetSelectOnDoubleClick(true);
			button->SetStringID(fileInfo.name);
			button->SetUserFunction(ItemCallback);
			indexContext->Add(button);
		}
		eventManager->SetDeviceImage(E_MOUSE, DM_VIEW);
	}

	// Reset the title and show buttons.
	titleField->SetText(messages->GetMessage(ZAF_MSG_HELP_INDEX));
	ZafIChar hotKeyChar;
	int hotKeyIndex;

#if !defined(__hpux)
    SetAutomaticUpdate(false);
#endif

	// Must subtract and re-add button in order to change hotkey setting.
	showButton->SetText(messages->GetMessage(ZAF_MSG_SHOW_TOPIC, false, &hotKeyChar, &hotKeyIndex));
	showButton->SetHotKey(hotKeyChar, hotKeyIndex);
	showButton->SetValue(S_HLP_SHOW_TOPIC);
	closeButton->SetText(messages->GetMessage(ZAF_MSG_CLOSE, false, &hotKeyChar, &hotKeyIndex));

	// Add the support fields.
#if !defined(__hpux)
    Add(indexTopic);
    Add(indexInstruction);
    Add(indexContext);
    Add(indexTitle);
#else
    indexTopic->SetVisible(true);
    indexInstruction->SetVisible(true);
    indexContext->SetVisible(true);
    indexTitle->SetVisible(true);
#endif 

#if defined(ZAF_USE_GEOMETRY_MANAGER)
	// Add the index constraints
	gmgr->Add(indexTopicConstraint);
	gmgr->Add(indexInstructionConstraint);
	gmgr->Add(indexTitleAttach);
	gmgr->Add(indexContextAttachRight);
	gmgr->Add(indexContextAttachBottom);
	gmgr->Add(indexContextDimension);

	// Reset the button constraint.
	gmgr->Subtract(showButtonAttach);
	delete showButtonAttach;
	showButtonAttach = new ZafAttachment(showButton, ZAF_ATCF_TOP);
	showButtonAttach->SetOppositeSide(true);
	showButtonAttach->SetOffset(6);
	showButtonAttach->SetReference(indexContext);
	gmgr->Add(showButtonAttach);
	gmgr->Subtract(closeButtonAttach);
	gmgr->Add(closeButtonAttach);
#endif

#if !defined(__hpux)
    SetAutomaticUpdate(true);
#endif
}

void ZafHelpSystem::AddTopicFields(ZafIChar *newHelpTitle, ZafIChar *newHelpContext)
{
	// Reset the title and context fields.
	topicTitle->SetText(newHelpTitle);
	topicContext->StringData()->SetText(newHelpContext, (int)(newHelpContext ? strlen(newHelpContext) : 0));

	// Reset the title and show buttons.
	titleField->SetText(messages->GetMessage(ZAF_MSG_HELP_TOPIC));
	ZafIChar hotKeyChar;
	int hotKeyIndex;

#if !defined(__hpux)
    SetAutomaticUpdate(false);
#endif

	// Must subtract and re-add button in order to change hotkey setting.
/*     Subtract(showButton);  */
	showButton->SetText(messages->GetMessage(ZAF_MSG_SHOW_INDEX, false, &hotKeyChar, &hotKeyIndex));
	showButton->SetHotKey(hotKeyChar, hotKeyIndex);
	showButton->SetValue(S_HLP_SHOW_INDEX);
	closeButton->SetText(messages->GetMessage(ZAF_MSG_CLOSE, false, &hotKeyChar, &hotKeyIndex));
/*     Add(showButton, closeButton);  */

	// Add the support fields.
#if !defined(__hpux)
    Add(topicTitle);
    Add(topicContext);
#else
    topicTitle->SetVisible(true);
    topicContext->SetVisible(true);
#endif
	
#if defined(ZAF_USE_GEOMETRY_MANAGER)
	// Add the topic constraints
	gmgr->Add(topicTitleConstraint);
	gmgr->Add(topicContextAttachRight);
	gmgr->Add(topicContextAttachBottom);
	gmgr->Add(topicContextDimension);

	// Reset the button constraint.
	gmgr->Subtract(showButtonAttach);
	delete showButtonAttach;
	showButtonAttach = new ZafAttachment(showButton, ZAF_ATCF_TOP);
	showButtonAttach->SetOppositeSide(true);
	showButtonAttach->SetOffset(6);
	showButtonAttach->SetReference(topicContext);
	gmgr->Add(showButtonAttach);
	gmgr->Subtract(closeButtonAttach);
	gmgr->Add(closeButtonAttach);
#endif

#if !defined(__hpux)
    SetAutomaticUpdate(true);
#endif
}

// Not used if geometry manager is present.
void ZafHelpSystem::ComputeGeometry(void)
{
	// Check for absolute window sizes.
	const int MIN_WIDTH = 50 * display->cellWidth;
	const int MIN_HEIGHT = 8 * display->cellHeight;
	ZafRegionStruct region = Region();
	if (!Minimized() &&
		(region.Width() < MIN_WIDTH || region.Height() < MIN_HEIGHT))
	{
		if (region.Width() < MIN_WIDTH)
		{
			region.right = region.left + MIN_WIDTH - 1;
			SetRegion(region);
		}
		if (region.Height() < MIN_HEIGHT)
		{
			region.bottom = region.top + MIN_HEIGHT - 1;
			SetRegion(region);
		}
		return;
	}

	// Perform geometry management on children.
	ZafRegionStruct maxRegion = MaxRegion(this);
	maxRegion.HzShift(-maxRegion.left);
	maxRegion.VtShift(-maxRegion.top);
	int buttonHeight = closeButton->Region().Height();
	int buttonWidth = closeButton->Region().Width();
	int hzSpacing = 2 * display->cellWidth;
	int vtSpacing = 2 * display->cellWidth;

	// right edge
	indexTopic->zafRegion.right =
		indexInstruction->zafRegion.right =
		indexTitle->zafRegion.right =
		indexContext->zafRegion.right =
		topicTitle->zafRegion.right =
		topicContext->zafRegion.right = maxRegion.right - hzSpacing;

	// bottom edge
	region = showButton->Region();
	region.bottom = maxRegion.bottom - vtSpacing;
	region.top = closeButton->Region().bottom - buttonHeight + 1;
	showButton->SetRegion(region);

	region = closeButton->Region();
	region.right = maxRegion.right - hzSpacing;
	region.left = region.right - buttonWidth + 1;
	region.bottom = maxRegion.bottom - vtSpacing;
	region.top = region.bottom - buttonHeight + 1;
	closeButton->SetRegion(region);

	indexContext->zafRegion.bottom = topicContext->zafRegion.bottom =
		closeButton->Region().top - vtSpacing;
}

void ZafHelpSystem::CreateGeneralFields(void)
{
	// Create the general support fields.
	Add(borderField = new ZafBorder);
	Add(new ZafMaximizeButton);
	Add(new ZafMinimizeButton);
	Add(new ZafSystemButton(ZAF_NATIVE_SYSTEM_BUTTON));
	ZafMessageData *messageData;
	messageData = messages->GetMessageData(ZAF_MSG_HELP_TOPIC);
	Add(titleField = new ZafTitle(messageData));

	ZafIcon *icon = new ZafIcon(0, 0, messages->GetMessage(ZAF_MSG_ICONTITLE),
		helpIcon, ZAF_MINIMIZE_ICON);
	Add(icon);

	ZafIChar hotKeyChar;
	int hotKeyIndex;
	messages->GetMessage(ZAF_MSG_SHOW_INDEX, false, &hotKeyChar, &hotKeyIndex);
	messageData = messages->GetMessageData(ZAF_MSG_SHOW_INDEX);
	showButton = new ZafButton(20, 90, 140, 8, messageData, 
		ZAF_NULLP(ZafBitmapData), ZAF_NATIVE_BUTTON);
	showButton->SetCoordinateType(ZAF_MINICELL);
	showButton->SetAutoSize(false);
	showButton->SetHotKey(hotKeyChar, hotKeyIndex);
	showButton->SetSendMessageWhenSelected(true);
	showButton->SetValue(S_HLP_SHOW_INDEX);

	Add(showButton);
	SetDefaultButton(showButton);

	closeButton = new ZafButton(480, 90, 140, 8, messages->GetMessage(ZAF_MSG_CLOSE, false, &hotKeyChar, &hotKeyIndex),
		ZAF_NULLP(ZafBitmapData), ZAF_NATIVE_BUTTON);
	closeButton->SetCoordinateType(ZAF_MINICELL);
	closeButton->SetAutoSize(false);
	closeButton->SetHotKey(hotKeyChar, hotKeyIndex);
	closeButton->SetSendMessageWhenSelected(true);
	closeButton->SetValue(S_HLP_CLOSE);

	Add(closeButton);

#if defined(ZAF_USE_GEOMETRY_MANAGER)
	// Set up the constraints and attachments on the buttons.
	ZafRelativeConstraint *rel = new ZafRelativeConstraint(showButton, ZAF_RLCF_RIGHT);
	rel->SetOppositeSide(true);
	rel->SetRatio(48);
	gmgr->Add(rel);

	showButtonAttach = new ZafAttachment(showButton, ZAF_ATCF_TOP);
	showButtonAttach->SetOppositeSide(true);
	showButtonAttach->SetOffset(6);
	showButtonAttach->SetReference(indexContext);
	gmgr->Add(showButtonAttach);

	rel = new ZafRelativeConstraint(closeButton, ZAF_RLCF_LEFT);
	rel->SetRatio(52);
	gmgr->Add(rel);

	closeButtonAttach = new ZafAttachment(closeButton, ZAF_ATCF_TOP);
	closeButtonAttach->SetOffset(0);
	closeButtonAttach->SetReference(showButton);
	gmgr->Add(closeButtonAttach);
#endif
}

void ZafHelpSystem::CreateIndexFields(void)
{
	// Create the index fields.
	indexTopic = new ZafPrompt(2, 0, 60, new ZafStringData(messages->GetMessage(ZAF_MSG_MESSAGE1)));
	indexTopic->SetHzJustify(ZAF_HZ_CENTER);
	Add(indexTopic);
	indexTopic->ConvertCoordinates(ZAF_PIXEL);
	indexTopic->SetFont(ZAF_FNT_SYSTEM);

	indexInstruction = new ZafPrompt(2, 1, 60, new ZafStringData(messages->GetMessage(ZAF_MSG_MESSAGE2)));
	indexInstruction->SetHzJustify(ZAF_HZ_CENTER);
	Add(indexInstruction);
	indexInstruction->ConvertCoordinates(ZAF_PIXEL);

	indexTitle = new ZafString(2, 2, 60, new ZafStringData(ZafLanguageManager::blankString, 100));
	Add(indexTitle);
	indexTitle->ConvertCoordinates(ZAF_PIXEL);

	indexContext = new ZafVtList(2, 3, 60, 5);
	indexContext->SetAutoSortData(true);
	ZafScrollBar *indexScroll = new ZafScrollBar(0, 0, 0, 0, ZAF_NULLP(ZafScrollData), ZAF_VERTICAL_SCROLL);
	indexScroll->SetSupportObject(true);
	indexContext->Add(indexScroll);
	Add(indexContext);
	indexContext->ConvertCoordinates(ZAF_PIXEL);

#if defined(ZAF_USE_GEOMETRY_MANAGER)
	indexTopicConstraint = new ZafRelativeConstraint(indexTopic, ZAF_RLCF_LEFT);
	indexTopicConstraint->SetCenter(true);
	indexTopicConstraint->SetRatio(50);
	gmgr->Add(indexTopicConstraint);

	indexInstructionConstraint = new ZafRelativeConstraint(indexInstruction, ZAF_RLCF_LEFT);
	indexInstructionConstraint->SetCenter(true);
	indexInstructionConstraint->SetRatio(50);
	gmgr->Add(indexInstructionConstraint);

	indexTitleAttach = new ZafAttachment(indexTitle, ZAF_ATCF_RIGHT);
	indexTitleAttach->SetOffset(2);
	indexTitleAttach->SetStretch(true);
	gmgr->Add(indexTitleAttach);

	indexContextAttachRight = new ZafAttachment(indexContext, ZAF_ATCF_RIGHT);
	indexContextAttachRight->SetOffset(2);
	indexContextAttachRight->SetStretch(true);
	gmgr->Add(indexContextAttachRight);
	indexContextAttachBottom = new ZafAttachment(indexContext, ZAF_ATCF_BOTTOM);
	indexContextAttachBottom->SetOffset(2);
	indexContextAttachBottom->SetStretch(true);
	gmgr->Add(indexContextAttachBottom);

	indexContextDimension = new ZafDimensionConstraint(indexContext, ZAF_DNCF_HEIGHT);
	indexContextDimension->SetMinimum(3);
	gmgr->Add(indexContextDimension);
#endif
}

void ZafHelpSystem::CreateTopicFields(void)
{
	// Create the topic fields.
	topicTitle = new ZafPrompt(2, 0, 60, new ZafStringData());
	topicTitle->SetHzJustify(ZAF_HZ_CENTER);
	Add(topicTitle);
	topicTitle->ConvertCoordinates(ZAF_PIXEL);
	topicTitle->SetFont(ZAF_FNT_SYSTEM);

	topicContext = new ZafText(2, 2, 60, 6, new ZafStringData(ZAF_ITEXT(""), -1, false));
	topicContext->SetBordered(true);
	topicContext->SetViewOnly(true);
	topicContext->SetStringID(_topicStringID);
	ZafScrollBar *topicScroll = new ZafScrollBar(0, 0, 0, 0,
		ZAF_NULLP(ZafScrollData), ZAF_VERTICAL_SCROLL);
	topicScroll->SetSupportObject(true);
	topicContext->Add(topicScroll);
	Add(topicContext);
	topicContext->ConvertCoordinates(ZAF_PIXEL);

#if defined(ZAF_USE_GEOMETRY_MANAGER)
	topicTitleConstraint = new ZafRelativeConstraint(topicTitle, ZAF_RLCF_LEFT);
	topicTitleConstraint->SetCenter(true);
	topicTitleConstraint->SetRatio(50);
	gmgr->Add(topicTitleConstraint);

	topicContextAttachRight = new ZafAttachment(topicContext, ZAF_ATCF_RIGHT);
	topicContextAttachRight->SetOffset(2);
	topicContextAttachRight->SetStretch(true);
	gmgr->Add(topicContextAttachRight);
	topicContextAttachBottom = new ZafAttachment(topicContext, ZAF_ATCF_BOTTOM);
	topicContextAttachBottom->SetOffset(2);
	topicContextAttachBottom->SetStretch(true);
	gmgr->Add(topicContextAttachBottom);

	topicContextDimension = new ZafDimensionConstraint(topicContext, ZAF_DNCF_HEIGHT);
	topicContextDimension->SetMinimum(4);
	gmgr->Add(topicContextDimension);
#endif
}

void ZafHelpSystem::DisplayHelp(const ZafIChar *name)
{
	bool displayHelp = false;

	// Try to find a matching help context.
	if (name && name[0])
	{
		if (!helpStorage)
			return;
		// Move to the help directory.
		helpStorage->ChDir(ZafFileSystem::rootDirectoryName);
		helpStorage->ChDir(className);

		// See if the name is a direct search.
		ZafIChar title[256], *context = ZAF_NULLP(ZafIChar);
		ZafFileInfoStruct fileInfo;
		int findError = helpStorage->FindFirst(fileInfo, name);
		if (!findError)
		{
			displayHelp = true;
			helpStorage->ChDir(fileInfo.name);
			ZafFile *hStorage = helpStorage->Open(_dataName, ZAF_FILE_READ);
			hStorage->Read(title, 256);
			hStorage->Read(&context);
			helpStorage->Close(hStorage);
			helpStorage->ChDir(ZafFileSystem::parentDirectoryName);
			RemoveIndexFields();
			AddTopicFields(title, context);
			if (context)
				delete []context;
		}
		else
		{
			// Try to match against the help system titles.
			int length = (int)strlen(name);
			helpStorage->ChDir(ZafFileSystem::rootDirectoryName);
			helpStorage->ChDir(className);
			for (int finished = helpStorage->FindFirst(fileInfo, _matchAll);
			 	findError && !finished; finished = helpStorage->FindNext(fileInfo, _matchAll))
				if (streq(fileInfo.name, ZafFileSystem::currentDirectoryName) &&
					streq(fileInfo.name, ZafFileSystem::parentDirectoryName))
				{
					helpStorage->ChDir(fileInfo.name);
					ZafFile *hObject = helpStorage->Open(ZAF_ITEXT("objectData"), ZAF_FILE_READ);
					helpStorage->ChDir(ZafFileSystem::parentDirectoryName);
					hObject->Read(title, 256);
					if (!strnicmp(name, title, length))
					{
						displayHelp = true;
						findError = false;
						hObject->Read(&context);
						RemoveIndexFields();
						AddTopicFields(title, context);
						if (context)
							delete []context;

						// Update the list field.
						for (ZafWindowObject *object = indexContext->First(); object; object = object->Next())
							if (!streq(fileInfo.name, object->StringID()))
							{
								// Make the object current and selected.
								object->SetSelected(true);
								indexContext->Add(object);
								indexTitle->StringData()->SetText(DynamicPtrCast(object, ZafButton)->Text());
								break;
							}
					}
					helpStorage->Close(hObject);
				}
		}
	}
	else
	{
		displayHelp = true;
		RemoveTopicFields();
		AddIndexFields();
	}

	// If we found an appropriate context, or no context was requested, 
	// display the help system.
	if (displayHelp)
	{
		// Invoke the index help.
		if (zafWindowManager->Index(this) == -1)
			zafWindowManager->Add(this);
		else
			SetFocus(true);
	}
}

ZafEventType ZafHelpSystem::Event(const ZafEventStruct &event)
{
	// Switch on the event.
	ZafEventType ccode = event.type;
	switch (ccode)
	{
#if !defined(ZAF_USE_GEOMETRY_MANAGER)
	case N_SIZE:
		ComputeGeometry();
		ccode = ZafWindow::Event(event);
		break;
#endif

	// In Motif if the current window is modal and the help system is called 
	// the help system must also be made modal to access it.  To prevent the 
	// help system from remaining modal the modal attribute must be set to false.
	case S_DEINITIALIZE:
		// Because we have a screenID we cheat and just set modal false.
		modal = false;
        ccode = ZafWindow::Event(event);
        break;

	case S_HLP_CLOSE:
		zafWindowManager->Subtract(this);	// Remove the help topic window.
		zafEventManager->Put(S_CONTINUE);
		break;

	case S_HLP_SHOW_INDEX:
		RemoveTopicFields();
		AddIndexFields();
#if defined(ZAF_USE_GEOMETRY_MANAGER)
		// Force the geometry manager to recompute.
		Event(N_SIZE);
#endif
		break;

	case S_HLP_SHOW_TOPIC:
		// Display the help context.
		DisplayHelp(indexTitle->Text());

#if defined(ZAF_USE_GEOMETRY_MANAGER)
		// Force the geometry manager to recompute.
		Event(N_SIZE);
#endif
		break;

	case S_HLP_SELECT_TOPIC:
		// Display the help context.
		DisplayHelp(event.windowObject->HelpContext());

#if defined(ZAF_USE_GEOMETRY_MANAGER)
		// Force the geometry manager to recompute.
		Event(N_SIZE);
#endif
		break;

	case S_HLP_UPDATE_NAME:
		// Reset the title field.  This message is sent from ItemCallback().
		indexTitle->StringData()->SetText(event.windowObject->Text());
		break;

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

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

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

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

ZafEventType ZafHelpSystem::ItemCallback(ZafWindowObject *object, ZafEventStruct &, ZafEventType ccode)
{
	// Check for selection of the field.
	if (ccode == L_DOUBLE_CLICK || ccode == L_SELECT)
	{
		// Update the help context selection.
		ZafEventStruct tEvent;
		tEvent.type = S_HLP_UPDATE_NAME;
		tEvent.windowObject = object;
		object->eventManager->Put(tEvent);
		// Show the associated help.
		if (ccode == L_DOUBLE_CLICK)
		{
			tEvent.type = S_HLP_SELECT_TOPIC;
			object->eventManager->Put(tEvent);
		}
	}
	return (0);
}

void ZafHelpSystem::RemoveIndexFields(void)
{
	// Remove the support fields.
#if !defined(__hpux)
    Subtract(indexTopic);
    Subtract(indexInstruction);
    Subtract(indexTitle);
    Subtract(indexContext);
#else
    indexTopic->SetVisible(false);
    indexInstruction->SetVisible(false);
    indexTitle->SetVisible(false);
    indexContext->SetVisible(false);
#endif

#if defined(ZAF_USE_GEOMETRY_MANAGER)
	// Subtract the index constraints
	gmgr->Subtract(indexTopicConstraint);
	gmgr->Subtract(indexInstructionConstraint);
	gmgr->Subtract(indexTitleAttach);
	gmgr->Subtract(indexContextAttachRight);
	gmgr->Subtract(indexContextAttachBottom);
	gmgr->Subtract(indexContextDimension);
#endif
}

void ZafHelpSystem::RemoveTopicFields(void)
{
	// Remove the support fields.
#if !defined(__hpux)
    Subtract(topicTitle);
    Subtract(topicContext);
#else
    topicTitle->SetVisible(false);
    topicContext->SetVisible(false);
#endif

#if defined(ZAF_USE_GEOMETRY_MANAGER)
	// Subtract the topic constraints
	gmgr->Subtract(topicTitleConstraint);
	gmgr->Subtract(topicContextAttachRight);
	gmgr->Subtract(topicContextAttachBottom);
	gmgr->Subtract(topicContextDimension);
#endif
}

void ZafHelpSystem::ResetStorage(ZafFileSystem *_helpStorage)
{
	// Reset the storage and update the index fields.
	if (_helpStorage == helpStorage)
		return;

	helpStorage = _helpStorage;
	indexContext->Destroy();
}

void ZafHelpSystem::ImageAllocate(void)
{
#if !defined(ZAF_TEXT_MODE)
	// Initialize the images.
	if (!helpIcon)
	{
		ZafI18nData::AddStaticModule(ImageFree);
		helpIcon = new ZafIconData(_help_ZafIcon);
		helpIcon->SetDestroyable(false);
	}
#endif
}

void ZafHelpSystem::ImageFree(bool globalRequest)
{
#if !defined(ZAF_TEXT_MODE)
	// Destroy the static images.
	if (globalRequest && helpIcon)
	{
		delete helpIcon;
		helpIcon = ZAF_NULLP(ZafIconData);
	}
#endif
}
