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

  1. //    Zinc Interface Library - PULLDN.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_PULL_DOWN_MENU::UIW_PULL_DOWN_MENU(int a_indentation, USHORT a_woFlags,
  9.     USHORT a_woAdvancedFlags) :
  10.     UIW_WINDOW(0, 0, 1, 1, a_woFlags | WOF_NON_FIELD_REGION,
  11.         a_woAdvancedFlags | WOAF_NORMAL_HOT_KEYS | WOAF_NO_SIZE | WOAF_NO_MOVE)
  12. {
  13.     // Initialize the pull-down menu information.
  14.     windowID[0] = ID_PULL_DOWN_MENU;
  15.     windowID[1] = ID_MENU;
  16.     windowID[2] = ID_WINDOW;
  17.     search.type = ID_PULL_DOWN_MENU;
  18.  
  19.     hotKey = HOT_KEY_SUB_WINDOW;
  20.     indentation = a_indentation;
  21. }
  22.  
  23. UIW_PULL_DOWN_MENU::UIW_PULL_DOWN_MENU(int a_indentation, UI_ITEM *flagItem) :
  24.     UIW_WINDOW(0, 0, 1, 1, WOF_BORDER | WOF_NON_FIELD_REGION,
  25.     WOAF_NO_FLAGS | WOAF_NORMAL_HOT_KEYS | WOAF_NO_SIZE | WOAF_NO_MOVE), 
  26.     indentation(a_indentation)
  27. {
  28.     // Initialize the pull-down menu information.
  29.     windowID[0] = ID_PULL_DOWN_MENU;
  30.     windowID[1] = ID_MENU;
  31.     windowID[2] = ID_WINDOW;
  32.     search.type = ID_PULL_DOWN_MENU;
  33.  
  34.     hotKey = HOT_KEY_SUB_WINDOW;
  35.     for (int i = 0; flagItem[i].string; i++)
  36.     {
  37.         UIW_PULL_DOWN_ITEM *item = new UIW_PULL_DOWN_ITEM(flagItem[i].string,
  38.             MNF_NO_FLAGS, flagItem[i].userFunction, flagItem[i].value);
  39.         *this + item;
  40.     }
  41. }
  42.  
  43. UIW_PULL_DOWN_MENU::Event(const UI_EVENT &event)
  44. {
  45.     // Switch on the event type.
  46.     UI_EVENT tEvent = event;
  47.     int ccode = UI_WINDOW_OBJECT::LogicalEvent(event, ID_MENU);
  48.     UIW_PULL_DOWN_ITEM *item;
  49.     switch (ccode)
  50.     {
  51.     case S_CREATE:
  52.     case S_SIZE:
  53.         if (display->isText)
  54.             woFlags &= ~WOF_BORDER;
  55.         else
  56.             woFlags |= WOF_BORDER;
  57.         woAdvancedStatus &= ~WOAS_INVALID_REGION;
  58.         if (!parent)
  59.         {
  60.             true.left = true.top = 0;
  61.             true.right = display->columns - 1;
  62.             true.bottom = display->lines - 1;
  63.         }
  64.         else
  65.         {
  66.             UI_WINDOW_OBJECT::RegionMax(TRUE);
  67.             if (true.bottom - true.top < display->cellHeight - 1)
  68.             {
  69.                 woAdvancedStatus |= WOAS_INVALID_REGION;
  70.                 break;
  71.             }
  72.             if (!display->isText &&
  73.                 parent->true.left < true.left &&
  74.                 parent->true.right > true.right &&
  75.                 parent->true.top < true.top)
  76.             {
  77.                 true.left--;
  78.                 true.top--;
  79.                 true.right++;
  80.             }
  81.         }
  82.  
  83.         int trueLeft = true.left;
  84.         int trueTop = true.top;
  85.         true.left += indentation * display->cellWidth;
  86.         int bottom = true.top;
  87.         for (item = First(); item; item = item->Next())
  88.         {
  89.             item->InformationSet(screenID, display, eventManager,
  90.                 windowManager, paletteMapTable, this);
  91.             item->Event(event);
  92.             item->true.right = item->true.left + item->relative.right;
  93.             item->true.bottom = item->true.top + display->cellHeight - 1;
  94.             if (item->true.bottom > true.bottom)
  95.                 item->woAdvancedStatus |= WOAS_INVALID_REGION;
  96.             else if (!FlagSet(item->woAdvancedStatus, WOAS_INVALID_REGION))
  97.                 bottom = item->true.bottom;
  98.             true.top = (display->isText) ? item->true.top : item->true.top - 1;
  99.         }
  100.         true.left = trueLeft;
  101.         true.top = trueTop;
  102.         if (bottom == true.top)
  103.             bottom += display->cellHeight - 1;
  104.         true.bottom = (display->isText) ? bottom : bottom + 1;
  105.          UIW_WINDOW::RegionsCompute();
  106.         break;
  107.  
  108.     case L_BEGIN_SELECT:
  109.     case L_CONTINUE_SELECT:
  110.         for (UIW_PULL_DOWN_ITEM *t_item = First(); t_item; t_item = t_item->Next())
  111.             if (!FlagSet(t_item->woFlags, WOF_NON_SELECTABLE) &&
  112.                 t_item->Overlap(event.position))
  113.                 break;
  114.  
  115.         // See if it is a new current item.
  116.         if (ccode == L_CONTINUE_SELECT && (!t_item ||
  117.             t_item == (UIW_PULL_DOWN_ITEM *)UI_LIST::Get(UIW_WINDOW::FindStatus, &WOS_CURRENT)))
  118.             break;
  119.  
  120.         // Unhighlight the remaining items.
  121.         UI_EVENT t_event;
  122.         t_event.type = S_DISPLAY_ACTIVE;
  123.         for (item = First(); item; item = item->Next())
  124.             if (item != t_item && FlagSet(item->woStatus, WOS_SELECTED))
  125.             {
  126.                 item->woStatus &= ~WOS_SELECTED;
  127.                 t_event.region = item->true;
  128.                 item->Event(t_event);
  129.             }
  130.  
  131.         // Process the key.
  132.         t_event = event;
  133.         t_event.type = L_BEGIN_SELECT;
  134.         ccode = UIW_WINDOW::Event(t_event);
  135.         break;
  136.  
  137.     case L_DOWN:
  138.         item = (UIW_PULL_DOWN_ITEM *)UI_LIST::Get(UIW_WINDOW::FindStatus, &WOS_CURRENT);
  139.         if (!item || !item->menu.First())
  140.             break;
  141.         tEvent.type = L_SELECT;
  142.         ccode = UIW_WINDOW::Event(tEvent);
  143.         break;
  144.  
  145.     case L_LEFT:
  146.     case L_RIGHT:
  147.         tEvent.type = (ccode == L_LEFT) ? L_PREVIOUS : L_NEXT;
  148.         if (FlagSet(woFlags, WOF_NON_FIELD_REGION))
  149.         {
  150.             UI_WINDOW_OBJECT *tParent = parent;
  151.             parent = NULL;        // Trick the window.
  152.             ccode = UIW_WINDOW::Event(tEvent);
  153.             parent = tParent;
  154.         }
  155.         else
  156.             ccode = UIW_WINDOW::Event(tEvent);
  157.         break;
  158.  
  159.     case L_TOP:
  160.     case L_BOTTOM:
  161.         tEvent.type = (ccode == L_TOP) ? L_FIRST : L_LAST;
  162.         ccode = UIW_WINDOW::Event(tEvent);
  163.         break;
  164.  
  165.     default:
  166.         ccode = UIW_WINDOW::Event(event);
  167.         break;
  168.     }
  169.  
  170.     // Return the event control code.
  171.     return (ccode);
  172. }
  173.  
  174. #ifdef ZIL_LOAD
  175. UIW_PULL_DOWN_MENU::UIW_PULL_DOWN_MENU(const char *name, UI_STORAGE *file, USHORT loadFlags) :
  176.     UIW_WINDOW(name, file, loadFlags | L_SUB_LEVEL)
  177. {
  178.     windowID[0] = ID_PULL_DOWN_MENU;
  179.     windowID[1] = ID_MENU;
  180.     windowID[2] = ID_WINDOW;
  181.     hotKey = HOT_KEY_SUB_WINDOW;
  182.  
  183.     if (!file)
  184.         file = _storage;
  185.     file->Load(&indentation);
  186.     if (!FlagSet(loadFlags, L_SUB_LEVEL) && FlagSet(file->stStatus, STS_TEMPORARY))
  187.         delete file;
  188. }
  189. #endif
  190.  
  191. #ifdef ZIL_STORE
  192. void UIW_PULL_DOWN_MENU::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
  193. {
  194.     UIW_WINDOW::Store(name, file, storeFlags | S_SUB_LEVEL);
  195.     file->Store(indentation);
  196.     if (!FlagSet(storeFlags, S_SUB_LEVEL))
  197.         file->ObjectSize(name, search);
  198. }
  199. #endif
  200.