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

  1. //    Zinc Interface Library - PULLDN1.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. #pragma argsused
  10. void UIW_PULL_DOWN_ITEM::UserFunction(UI_EVENT &event)
  11. {
  12.     UIW_POP_UP_ITEM *item;
  13.     if (parent->hMenu)
  14.     {
  15.         // Get the menu element from the event.rawCode index.
  16.         int index = event.rawCode & 0x00FF;
  17.         for (item = menu.First(); index && item; item = item->Next())
  18.             index--;
  19.         if (item)
  20.             item->Event(event);
  21.     }
  22. }
  23.  
  24. UIW_PULL_DOWN_ITEM::UIW_PULL_DOWN_ITEM(char *_string, USHORT _mnFlags,
  25.     void (*_userFunction)(void *object, UI_EVENT &event), USHORT _value) :
  26.     UIW_BUTTON(0, 0, strlen(_string), NULL, BTF_DOWN_CLICK | BTF_NO_TOGGLE | BTF_NO_3D,
  27.         WOF_NON_FIELD_REGION, UIW_PULL_DOWN_ITEM::PullDownUserFunction, _value),
  28.     menu(0, 0, _mnFlags | MNF_SELECT_LEFT | MNF_SELECT_RIGHT, WOF_BORDER, WOAF_TEMPORARY | WOAF_NO_DESTROY)
  29. {
  30.     // Initialize the menu item information.
  31.     windowID[0] = ID_PULL_DOWN_ITEM;
  32.     windowID[1] = ID_MENU_ITEM;
  33.     windowID[2] = ID_BUTTON;
  34.     search.type = ID_PULL_DOWN_ITEM;
  35.  
  36.     woFlags &= ~WOF_BORDER;
  37.     userFunction = _userFunction ? _userFunction : UIW_PULL_DOWN_ITEM::PullDownUserFunction;
  38.  
  39.     if (!_string)
  40.         return;
  41.     string = FlagSet(woFlags, WOF_NO_ALLOCATE_DATA) ? _string : ui_strdup(_string);
  42. }
  43.  
  44. UIW_PULL_DOWN_ITEM::UIW_PULL_DOWN_ITEM(char *_string, USHORT _mnFlags, UI_ITEM *flagItem) :
  45.     UIW_BUTTON(0, 0, strlen(_string), NULL, BTF_DOWN_CLICK | BTF_NO_TOGGLE | BTF_NO_3D,
  46.         WOF_NON_FIELD_REGION, UIW_PULL_DOWN_ITEM::PullDownUserFunction, 0),
  47.     menu(0, 0, _mnFlags | MNF_SELECT_LEFT | MNF_SELECT_RIGHT, WOF_BORDER, WOAF_TEMPORARY | WOAF_NO_DESTROY)
  48. {
  49.     // Initialize the menu item information.
  50.     windowID[0] = ID_PULL_DOWN_ITEM;
  51.     windowID[1] = ID_MENU_ITEM;
  52.     windowID[2] = ID_BUTTON;
  53.     search.type = ID_PULL_DOWN_ITEM;
  54.  
  55.     woFlags &= ~WOF_BORDER;
  56.     userFunction = UIW_PULL_DOWN_ITEM::PullDownUserFunction;
  57.     for (int i = 0; flagItem[i].string; i++)
  58.     {
  59.         UIW_POP_UP_ITEM *item = (flagItem[i].string[0] != '\0') ?
  60.             new UIW_POP_UP_ITEM(flagItem[i].string, MNIF_NO_FLAGS,
  61.                 BTF_NO_TOGGLE, WOF_NO_FLAGS, flagItem[i].userFunction) :
  62.             new UIW_POP_UP_ITEM;
  63.         item->value = flagItem[i].value;
  64.         menu.Add(item);
  65.     }
  66.  
  67.     if (!_string)
  68.         return;
  69.     string = FlagSet(woFlags, WOF_NO_ALLOCATE_DATA) ? _string : ui_strdup(_string);
  70. }
  71.  
  72. void UIW_PULL_DOWN_ITEM::DataSet(char *newString)
  73. {
  74.     // Reset the button's string information.
  75.     if (newString)
  76.     {
  77.         if (FlagSet(woFlags, WOF_NO_ALLOCATE_DATA))
  78.             string = newString;
  79.         else
  80.         {
  81.             if (string)
  82.                 delete string;
  83.             string = (newString) ? ui_strdup(newString) : 0;
  84.         }
  85.     }
  86.  
  87.     // Modify MS Windows menu.
  88.     if (parent && parent->hMenu && string)
  89.     {
  90.         UIW_PULL_DOWN_ITEM *item = this;
  91.         for (int count = 0; item; item->Previous())
  92.             count++;
  93.         ModifyMenu(parent->hMenu, MF_BYCOMMAND, MF_STRING, count, string);
  94.         DrawMenuBar(screenID);
  95.     }
  96.     else
  97.     {
  98.         if (parent)
  99.             parent->Redisplay(TRUE);
  100.         else
  101.             UI_WINDOW_OBJECT::Redisplay(TRUE);
  102.     }
  103. }
  104.  
  105. UIW_PULL_DOWN_ITEM::Event(const UI_EVENT &event)
  106. {
  107.     int ccode = event.type;
  108.     UIW_POP_UP_ITEM *item;
  109.     switch (ccode)
  110.     {
  111.     case S_INITIALIZE:
  112.         //Create the MS Windows menu if any items exist.
  113.         hMenu = NULL;
  114.         if (First())
  115.             hMenu = CreatePopupMenu();
  116.  
  117.         // Add item - event.rawCode ID number.
  118.         char *tHotKey = NULL;
  119.         if (string)
  120.             tHotKey = strchr(string, '~');
  121.         if (tHotKey)
  122.             hotKey = toupper(tHotKey[1]);
  123.         ui_strrepc(string, '~', '&');
  124.  
  125.         int count = event.rawCode;
  126.         for (item = First(); item; item = item->Next())
  127.         {
  128.             if (!item->userFunction && item->NumberID() > 0xFF00)
  129.                 item->userFunction = UIW_POP_UP_ITEM::PopUpItemUserFunction;
  130.             item->Event(event);
  131.             item->hMenu = hMenu;
  132.             if (FlagSet(item->mniFlags, MNIF_SEPARATOR))
  133.                 AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
  134.             else
  135.                 AppendMenu(hMenu, MF_STRING, count, (LPSTR)item->DataGet());
  136.             count++;
  137.         }
  138.  
  139.         if (parent && parent->hMenu && hMenu)
  140.             AppendMenu(parent->hMenu, MF_STRING | MF_POPUP, hMenu, string);
  141.         else if (parent && parent->hMenu)
  142.             AppendMenu(parent->hMenu, MF_STRING, count, string);
  143.         break;
  144.  
  145.     case S_CREATE:
  146.         menu.InformationSet(0, display, eventManager, windowManager, 
  147.             paletteMapTable, this);
  148.  
  149.         for (item = First(); item; item = item->Next())
  150.             item->InformationSet(0, display, eventManager, windowManager, 
  151.                 paletteMapTable, this);
  152.  
  153.         relative.left = relative.top = relative.right =    relative.bottom = 0;
  154.         ccode = UIW_BUTTON::Event(event);
  155.         break;
  156.  
  157.     case S_MENU_SELECT:
  158.         {
  159.         UI_EVENT tEvent = event;
  160.         tEvent.type = L_SELECT;
  161.         ccode = UIW_BUTTON::Event(tEvent);
  162.         break;
  163.         }
  164.  
  165.     default:
  166.         ccode = UIW_BUTTON::Event(event);
  167.         break;
  168.     }
  169.  
  170.     // Return the event control code.
  171.     return (ccode);
  172. }
  173.  
  174. void *UIW_PULL_DOWN_ITEM::Information(INFORMATION_REQUEST request, void *data)
  175. {
  176.     if (request == GET_NUMBERID_OBJECT || request == GET_STRINGID_OBJECT)
  177.         return (menu.Information(request, data));
  178.     else if (request == PRINT_INFORMATION)
  179.     {
  180.         UI_WINDOW_OBJECT::Information(request, data);
  181.         return (menu.Information(request, data));
  182.     }
  183.     else
  184.         return (UI_WINDOW_OBJECT::Information(request, data));
  185. }
  186.  
  187. #ifdef ZIL_LOAD
  188. UIW_PULL_DOWN_ITEM::UIW_PULL_DOWN_ITEM(const char *name, UI_STORAGE *file, USHORT loadFlags) :
  189.     UIW_BUTTON(name, file, loadFlags | L_SUB_LEVEL), menu(0, file, L_SUB_LEVEL)
  190. {
  191.     windowID[0] = ID_PULL_DOWN_ITEM;
  192.     windowID[1] = ID_MENU_ITEM;
  193.     windowID[2] = ID_BUTTON;
  194.  
  195.     userFunction = UIW_PULL_DOWN_ITEM::PullDownUserFunction;
  196.     if (!file)
  197.         file = _storage;
  198.     if (!FlagSet(loadFlags, L_SUB_LEVEL) && FlagSet(file->stStatus, STS_TEMPORARY))
  199.         delete file;
  200. }
  201. #endif
  202.  
  203. #ifdef ZIL_STORE
  204. void UIW_PULL_DOWN_ITEM::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
  205. {
  206.     UIW_BUTTON::Store(name, file, storeFlags | S_SUB_LEVEL);
  207.     menu.Store(0, file, S_SUB_LEVEL | S_SKIP_TYPE);
  208.     if (!FlagSet(storeFlags, S_SUB_LEVEL))
  209.         file->ObjectSize(name, search);
  210. }
  211. #endif
  212.