home *** CD-ROM | disk | FTP | other *** search
- // Zinc Interface Library - HELPWIN.CPP
- // COPYRIGHT (C) 1990, 1991. All Rights Reserved.
- // Zinc Software Incorporated. Pleasant Grove, Utah USA
-
- #include "ui_win.hpp"
- #include <string.h>
-
- static char *_defaultTitle = "No Help";
- static char *_defaultMessage = "\nNo help available at this point.";
- static char *_errorMessage = "The help file %s could not be opened.";
-
- UI_HELP_WINDOW_SYSTEM::UI_HELP_WINDOW_SYSTEM(char *_helpFileName,
- UI_WINDOW_MANAGER *windowManager, USHORT _defaultHelpContext) :
- UIW_WINDOW(10, 3, -10, 12, WOF_NO_FLAGS, WOAF_NO_DESTROY),
- installed(FALSE), title(NULL), message(NULL),
- defaultHelpContext(_defaultHelpContext)
- {
- // Open the help storage file.
- char helpFileName[128];
- strcpy(helpFileName, _helpFileName);
- UI_STORAGE::ChangeExtension(helpFileName, ".DAT");
- storage = new UI_STORAGE(helpFileName);
- if (FlagSet(storage->stStatus, STS_OPEN_ERROR))
- {
- delete storage;
- storage = NULL;
- _errorSystem->ReportError(windowManager, WOF_NO_FLAGS, _errorMessage, helpFileName);
- return;
- }
-
- // Create the help window.
- char *title = ui_strdup(_defaultTitle);
- char *message = ui_strdup(_defaultMessage);
- *this
- + new UIW_BORDER
- + new UIW_MAXIMIZE_BUTTON
- + new UIW_MINIMIZE_BUTTON
- + UIW_SYSTEM_BUTTON::Generic()
- + (titleField = new UIW_TITLE(title, WOF_NO_ALLOCATE_DATA | WOF_JUSTIFY_CENTER))
- + &(*new UIW_PULL_DOWN_MENU(0, WOF_NO_FLAGS, WOAF_NO_FLAGS)
- + new UIW_PULL_DOWN_ITEM(" ~Close ", MNF_NO_FLAGS,
- UI_HELP_WINDOW_SYSTEM::ItemClose))
- + new UIW_SCROLL_BAR(0, 0, 0, 0, SBF_VERTICAL, WOF_NON_FIELD_REGION)
- + (messageField = new UIW_TEXT(0, 0, 0, 0, message, strlen(message) + 1,
- TXF_NO_FLAGS, WOF_VIEW_ONLY | WOF_NO_ALLOCATE_DATA | WOF_NON_FIELD_REGION));
- this->paletteMapTable = _helpPaletteMapTable;
- installed = TRUE;
- }
-
- UI_HELP_WINDOW_SYSTEM::~UI_HELP_WINDOW_SYSTEM()
- {
- if (storage)
- delete storage;
- if (title)
- delete title;
- if (message)
- delete message;
- if (windowManager)
- *windowManager - this;
- }
-
- void UI_HELP_WINDOW_SYSTEM::DisplayHelp(UI_WINDOW_MANAGER *a_windowManager,
- USHORT helpContext)
- {
- // Make sure there is a storage unit.
- if (!installed || !storage)
- return;
- else if (helpContext == NO_HELP_CONTEXT)
- helpContext = defaultHelpContext;
-
- // Construct the new help message and title.
- delete title;
- delete message;
- UI_STORAGE_ELEMENT *element = (helpContext != NO_HELP_CONTEXT) ?
- storage->Seek(helpContext) : NULL;
- if (element)
- {
- storage->Load(&title);
- if (!title)
- strcpy(title, "");
- storage->Load(&message);
- if (!message)
- strcpy(message, "");
- }
- else
- {
- title = ui_strdup(_defaultTitle);
- message = ui_strdup(_defaultMessage);
- }
-
- // Show the help window.
- display = NULL;
- eventManager = NULL;
- windowManager = NULL;
- titleField->DataSet(title);
- messageField->DataSet(message, strlen(message) + 1);
- UI_WINDOW_OBJECT *object = a_windowManager->First();
- if (object && FlagSet(object->woAdvancedFlags, WOAF_MODAL))
- woAdvancedFlags |= WOAF_MODAL;
- else
- woAdvancedFlags &= ~WOAF_MODAL;
- *a_windowManager + this;
- }
-