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 / PROMPT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-01  |  3.0 KB  |  110 lines

  1. //    Zinc Interface Library - PROMPT.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 <ctype.h>
  7. #include <string.h>
  8.  
  9. UIW_PROMPT::UIW_PROMPT(int left, int top, char *_prompt, USHORT _woFlags) :
  10.     UI_WINDOW_OBJECT(left, top, ui_strlen(_prompt), 1, _woFlags | WOF_NON_SELECTABLE, WOAF_NO_FLAGS),
  11.     borderWidth(0), borderHeight(0)
  12. {
  13.     // Initialize the prompt information.
  14.     windowID[0] = ID_PROMPT;
  15.     search.type = ID_PROMPT;
  16.     prompt = ui_strdup(_prompt);
  17. }
  18.  
  19. UIW_PROMPT::UIW_PROMPT(int left, int top, int width, int height, char *_prompt, USHORT _woFlags) :
  20.     UI_WINDOW_OBJECT(left, top, width, height, _woFlags | WOF_NON_SELECTABLE, WOAF_NO_FLAGS), 
  21.     borderWidth(width), borderHeight(height)
  22. {
  23.     // Initialize the prompt information.
  24.     windowID[0] = ID_PROMPT;
  25.     search.type = ID_PROMPT;
  26.     prompt = ui_strdup(_prompt);
  27. }
  28.  
  29. void UIW_PROMPT::DataSet(char *_prompt)
  30. {
  31.     // Reset the prompt's string information.
  32.     if (prompt)
  33.         delete prompt;
  34.     prompt = ui_strdup(_prompt);
  35.     UI_WINDOW_OBJECT::Redisplay(FALSE);
  36. }
  37.  
  38. int UIW_PROMPT::Event(const UI_EVENT &event)
  39. {
  40.     // Switch on the event type.
  41.     int ccode = event.type;
  42.     switch (ccode)
  43.     {
  44.     case S_CREATE:
  45.     case S_SIZE:
  46.         char *tHotKey = strchr(prompt, '~');
  47.         display->RegionConvert(relative, &woStatus, WOS_GRAPHICS);
  48.         relative.right = relative.left + display->TextWidth(prompt) - 1;
  49.         if (display->isText && FlagSet(woFlags, WOF_BORDER))
  50.             relative.right += 2;
  51.         UI_WINDOW_OBJECT::RegionMax(TRUE);
  52.         if (tHotKey && next)
  53.         {
  54.             UI_WINDOW_OBJECT *object = Next();
  55.             object->hotKey = toupper(tHotKey[1]);
  56.         }
  57.         break;
  58.  
  59.     case S_CURRENT:
  60.     case S_NON_CURRENT:
  61.     case S_DISPLAY_ACTIVE:
  62.     case S_DISPLAY_INACTIVE:
  63.         if (!UI_WINDOW_OBJECT::NeedsUpdate(event, ccode))
  64.             break;
  65.         else if (borderWidth && borderHeight)
  66.         {
  67.             display->Rectangle(screenID, true.left, true.top,
  68.                 true.left + borderWidth * display->cellWidth - 1,
  69.                 true.top + borderHeight * display->cellHeight - 1,
  70.                 lastPalette, 1);
  71.             display->Text(screenID, true.left + display->cellWidth, true.top, prompt, lastPalette, -1);
  72.         }
  73.         else
  74.             UI_WINDOW_OBJECT::Text(prompt, 0, ccode, lastPalette);
  75.         break;
  76.  
  77.     default:
  78.         ccode = UI_WINDOW_OBJECT::Event(event);
  79.         break;
  80.     }
  81.  
  82.     // Return the control code.
  83.     return (ccode);
  84. }
  85.  
  86. #ifdef ZIL_LOAD
  87. UIW_PROMPT::UIW_PROMPT(const char *name, UI_STORAGE *file, USHORT loadFlags) :
  88.     UI_WINDOW_OBJECT(name, file, loadFlags | L_SUB_LEVEL),
  89.     borderWidth(0), borderHeight(0)
  90. {
  91.     windowID[0] = ID_PROMPT;
  92.  
  93.     if (!file)
  94.         file = _storage;
  95.     file->Load(&prompt);
  96.     if (!FlagSet(loadFlags, L_SUB_LEVEL) && FlagSet(file->stStatus, STS_TEMPORARY))
  97.         delete file;
  98. }
  99. #endif
  100.  
  101. #ifdef ZIL_STORE
  102. void UIW_PROMPT::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
  103. {
  104.     UI_WINDOW_OBJECT::Store(name, file, storeFlags | S_SUB_LEVEL);
  105.     file->Store(prompt);
  106.     if (!FlagSet(storeFlags, S_SUB_LEVEL))
  107.         file->ObjectSize(name, search);
  108. }
  109. #endif
  110.