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

  1. //    Zinc Interface Library - TITLE.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. UIW_TITLE::UIW_TITLE(char *title, USHORT _woFlags) :
  9.     UIW_BUTTON(0, 0, 0, title, BTF_DOWN_CLICK | BTF_NO_TOGGLE | BTF_NO_3D,
  10.     _woFlags | WOF_BORDER | WOF_NON_FIELD_REGION, UIW_TITLE::TitleUserFunction)
  11. {
  12.     // Initialize the title information.
  13.     windowID[0] = ID_TITLE;
  14.     windowID[1] = ID_BUTTON;
  15.     search.type = ID_TITLE;
  16.     search.numberID = NUMID_TITLE;
  17.     strcpy(search.stringID, "NUMID_TITLE");
  18.  
  19.     woAdvancedFlags |= WOAF_NON_CURRENT;
  20. }
  21.  
  22. void UIW_TITLE::DataSet(char *_string)
  23. {
  24.     // Reset the button's string information.
  25.     if (_string)
  26.     {
  27.         if (string && !FlagSet(woFlags, WOF_NO_ALLOCATE_DATA))
  28.             delete string;
  29.         string = FlagSet(woFlags, WOF_NO_ALLOCATE_DATA) ? _string : ui_strdup(_string);
  30.     }
  31.     if (display && display->isText)
  32.         UI_WINDOW_OBJECT::Redisplay(TRUE);
  33.     else
  34.         UI_WINDOW_OBJECT::Redisplay(FALSE);
  35. }
  36.  
  37. int UIW_TITLE::Event(const UI_EVENT &event)
  38. {
  39.     // Switch on the event type.
  40.     int ccode = UI_WINDOW_OBJECT::LogicalEvent(event, ID_TITLE);
  41.     switch (ccode)
  42.     {
  43.     case S_CREATE:
  44.         UIW_BUTTON::Event(event);
  45.         // Continue to S_SIZE.
  46.  
  47.     case S_SIZE:
  48.         if (display->isText)
  49.         {
  50.             int width = (parent && parent->hotKey) ? 
  51.                 strlen(string) - 1 : strlen(string);
  52.             if (FlagSet(woFlags, WOF_BORDER))
  53.                 width += 2;
  54.             true.top = true.bottom = parent->true.top;
  55.             int count = 0;
  56.             for (UI_WINDOW_OBJECT *object = Previous(); object;
  57.                 object = object->Previous())
  58.                 if (object->true.top == parent->true.top)
  59.                     count++;
  60.             if (count > 1)
  61.             {
  62.                 true.left = parent->true.left + 5;
  63.                 true.right = parent->true.right - 8;
  64.             }
  65.             else
  66.             {
  67.                 true.left = parent->true.left + 1;
  68.                 true.right = parent->true.right - 1;
  69.             }
  70.             if (width < true.right - true.left)
  71.             {
  72.                 if (FlagSet(woFlags, WOF_JUSTIFY_CENTER))
  73.                     true.left += (true.right - true.left - width + 1) / 2;
  74.                 else if (FlagSet(woFlags, WOF_JUSTIFY_RIGHT))
  75.                     true.left = true.right - width + 1;
  76.                 true.right = true.left + width - 1;
  77.             }
  78.         }
  79.         else
  80.         {
  81.             int height;
  82.             UI_WINDOW_OBJECT::Information(GET_DEFAULT_HEIGHT, &height);
  83.             UI_WINDOW_OBJECT::RegionMax(TRUE);
  84.             if (true.top > parent->true.top)
  85.                 true.top -= 1;
  86.             if (true.right < parent->true.right)
  87.                 true.right += 1;
  88.             if (true.left > parent->true.left)
  89.                 true.left -= 1;
  90.             true.bottom = true.top + height - 1;
  91.         }
  92.         break;
  93.  
  94.     case L_VIEW:
  95.         if (!FlagSet(parent->woAdvancedFlags, WOAF_NO_MOVE) &&
  96.             UI_WINDOW_OBJECT::Overlap(event.position))
  97.         {
  98.             UI_EVENT tEvent = event;
  99.             tEvent.rawCode = DM_MOVE;
  100.             eventManager->Event(tEvent);
  101.             break;
  102.         }
  103.         // Continue to default.
  104.  
  105.     case S_DISPLAY_ACTIVE:
  106.     case S_DISPLAY_INACTIVE:
  107.         if (display->isText)
  108.             lastPalette = NULL;
  109.         // Continue to default.
  110.  
  111.     default:
  112.         ccode = UIW_BUTTON::Event(event);
  113.         break;
  114.     }
  115.  
  116.     // Return the control code.
  117.     return (ccode);
  118. }
  119.  
  120.  
  121. #ifdef ZIL_LOAD
  122. UIW_TITLE::UIW_TITLE(const char *name, UI_STORAGE *file, USHORT loadFlags) :
  123.     UIW_BUTTON(name, file, loadFlags | L_SUB_LEVEL)
  124. {
  125.     windowID[0] = ID_TITLE;
  126.     windowID[1] = ID_BUTTON;
  127.     userFunction = UIW_TITLE::TitleUserFunction;
  128.  
  129.     if (!file)
  130.         file = _storage;
  131.     if (!FlagSet(loadFlags, L_SUB_LEVEL) && FlagSet(file->stStatus, STS_TEMPORARY))
  132.         delete file;
  133. }
  134. #endif
  135.  
  136. #ifdef ZIL_STORE
  137. void UIW_TITLE::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
  138. {
  139.     UIW_BUTTON::Store(name, file, storeFlags | S_SUB_LEVEL);
  140.     if (!FlagSet(storeFlags, S_SUB_LEVEL))
  141.         file->ObjectSize(name, search);
  142. }
  143. #endif
  144.