home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / ZINC_6.ZIP / DOSSRC.ZIP / HELPWIN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-01  |  3.1 KB  |  104 lines

  1. //    Zinc Interface Library - HELPWIN.CPP
  2. //    COPYRIGHT (C) 1990, 1991.  All Rights Reserved.
  3. //    Zinc Software Incorporated.  Pleasant Grove, Utah  USA
  4.  
  5. #include "ui_win.hpp"
  6. #include <string.h>
  7.  
  8. static char *_defaultTitle = "No Help";
  9. static char *_defaultMessage = "\nNo help available at this point.";
  10. static char *_errorMessage = "The help file %s could not be opened.";
  11.  
  12. UI_HELP_WINDOW_SYSTEM::UI_HELP_WINDOW_SYSTEM(char *_helpFileName,
  13.     UI_WINDOW_MANAGER *windowManager, USHORT _defaultHelpContext) :
  14.     UIW_WINDOW(10, 5, -10, -5, WOF_NO_FLAGS, WOAF_NO_DESTROY),
  15.     installed(FALSE), title(NULL), message(NULL),
  16.     defaultHelpContext(_defaultHelpContext)
  17. {
  18.     // Open the help storage file.
  19.     char helpFileName[128];
  20.     strcpy(helpFileName, _helpFileName);
  21.     UI_STORAGE::ChangeExtension(helpFileName, ".DAT");
  22.     storage = new UI_STORAGE(helpFileName);
  23.     if (FlagSet(storage->stStatus, STS_OPEN_ERROR))
  24.     {
  25.         delete storage;
  26.         storage = NULL;
  27.         _errorSystem->ReportError(windowManager, WOF_NO_FLAGS, _errorMessage, helpFileName);
  28.         return;
  29.     }
  30.  
  31.     // Create the help window.
  32.     char *title = ui_strdup(_defaultTitle);
  33.     char *message = ui_strdup(_defaultMessage);
  34.     *this
  35.         + new UIW_BORDER
  36.         + new UIW_MAXIMIZE_BUTTON
  37.         + new UIW_MINIMIZE_BUTTON
  38.         + UIW_SYSTEM_BUTTON::Generic()
  39.         + (titleField = new UIW_TITLE(title, WOF_NO_ALLOCATE_DATA | WOF_JUSTIFY_CENTER))
  40.         + &(*new UIW_PULL_DOWN_MENU(0, WOF_NO_FLAGS, WOAF_NO_FLAGS)
  41.             + new UIW_PULL_DOWN_ITEM(" ~Close ", MNF_NO_FLAGS,
  42.             UI_HELP_WINDOW_SYSTEM::ItemClose))
  43.         + new UIW_SCROLL_BAR(0, 0, 0, 0, SBF_VERTICAL, WOF_NON_FIELD_REGION)
  44.         + (messageField = new UIW_TEXT(0, 0, 0, 0, message, strlen(message) + 1,
  45.             TXF_NO_FLAGS, WOF_VIEW_ONLY | WOF_NO_ALLOCATE_DATA | WOF_NON_FIELD_REGION));
  46.     this->paletteMapTable = _helpPaletteMapTable;
  47.     installed = TRUE;
  48. }
  49.  
  50. UI_HELP_WINDOW_SYSTEM::~UI_HELP_WINDOW_SYSTEM()
  51. {
  52.     if (storage)
  53.         delete storage;
  54.     if (title)
  55.         delete title;
  56.     if (message)
  57.         delete message;
  58.     if (windowManager)
  59.         *windowManager - this;
  60. }
  61.  
  62. void UI_HELP_WINDOW_SYSTEM::DisplayHelp(UI_WINDOW_MANAGER *a_windowManager,
  63.     USHORT helpContext)
  64. {
  65.     // Make sure there is a storage unit.
  66.     if (!installed || !storage)
  67.         return;
  68.     else if (helpContext == NO_HELP_CONTEXT)
  69.         helpContext = defaultHelpContext;
  70.  
  71.     // Construct the new help message and title.
  72.     delete title;
  73.     delete message;
  74.     UI_STORAGE_ELEMENT *element = (helpContext != NO_HELP_CONTEXT) ?
  75.         storage->Seek(helpContext) : NULL;
  76.     if (element)
  77.     {
  78.         storage->Load(&title);
  79.         if (!title)
  80.             strcpy(title, "");
  81.         storage->Load(&message);
  82.         if (!message)
  83.             strcpy(message, "");
  84.     }
  85.     else
  86.     {
  87.         title = ui_strdup(_defaultTitle);
  88.         message = ui_strdup(_defaultMessage);
  89.     }
  90.  
  91.     // Show the help window.
  92.     display = NULL;
  93.     eventManager = NULL;
  94.     windowManager = NULL;
  95.     titleField->DataSet(title);
  96.     messageField->DataSet(message, strlen(message) + 1);
  97.     UI_WINDOW_OBJECT *object = a_windowManager->First();
  98.     if (object && FlagSet(object->woAdvancedFlags, WOAF_MODAL))
  99.         woAdvancedFlags |= WOAF_MODAL;
  100.     else
  101.         woAdvancedFlags &= ~WOAF_MODAL;
  102.     *a_windowManager + this;
  103. }
  104.