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 / PLLDN1.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-01  |  4.6 KB  |  154 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 <string.h>
  7.  
  8. #pragma argsused
  9. void UIW_PULL_DOWN_ITEM::UserFunction(UI_EVENT &event)
  10. {
  11.     woStatus &= ~WOS_SELECTED;
  12.     if (!menu.First())
  13.         return;
  14.  
  15.     for (UIW_POP_UP_ITEM *item = menu.First(); item; item = item->Next())
  16.         item->woStatus &= ~WOS_CURRENT;
  17.  
  18.     menu.true.left = (!previous && !display->isText) ? true.left - 1 : true.left;
  19.     menu.true.top = true.bottom + 1;
  20.     menu.true.right = menu.true.bottom = 0x0FFF;
  21.     if (display->isText)
  22.         menu.woStatus &= ~WOS_GRAPHICS;
  23.     else
  24.         menu.woStatus |= WOS_GRAPHICS;
  25.     event.type = S_CLOSE_TEMPORARY;
  26.     windowManager->Event(event);
  27.     *windowManager + &menu;
  28. }
  29.  
  30. UIW_PULL_DOWN_ITEM::UIW_PULL_DOWN_ITEM(char *_string, USHORT _mnFlags,
  31.     void (*_userFunction)(void *object, UI_EVENT &event), USHORT _value) :
  32.     UIW_BUTTON(0, 0, strlen(_string), _string, BTF_DOWN_CLICK | BTF_NO_TOGGLE | BTF_NO_3D,
  33.         WOF_NON_FIELD_REGION, UIW_PULL_DOWN_ITEM::PullDownUserFunction, _value),
  34.     menu(0, 0, _mnFlags | MNF_SELECT_LEFT | MNF_SELECT_RIGHT, WOF_BORDER, WOAF_TEMPORARY | WOAF_NO_DESTROY)
  35. {
  36.     // Initialize the menu item information.
  37.     windowID[0] = ID_PULL_DOWN_ITEM;
  38.     windowID[1] = ID_MENU_ITEM;
  39.     windowID[2] = ID_BUTTON;
  40.     search.type = ID_PULL_DOWN_ITEM;
  41.  
  42.     woFlags &= ~WOF_BORDER;
  43.     userFunction = _userFunction ? _userFunction : UIW_PULL_DOWN_ITEM::PullDownUserFunction;
  44. }
  45.  
  46. UIW_PULL_DOWN_ITEM::UIW_PULL_DOWN_ITEM(char *_string, USHORT _mnFlags, UI_ITEM *flagItem) :
  47.     UIW_BUTTON(0, 0, strlen(_string), _string, BTF_DOWN_CLICK | BTF_NO_TOGGLE | BTF_NO_3D,
  48.         WOF_NON_FIELD_REGION, UIW_PULL_DOWN_ITEM::PullDownUserFunction, 0),
  49.     menu(0, 0, _mnFlags | MNF_SELECT_LEFT | MNF_SELECT_RIGHT, WOF_BORDER, WOAF_TEMPORARY | WOAF_NO_DESTROY)
  50. {
  51.     // Initialize the menu item information.
  52.     windowID[0] = ID_PULL_DOWN_ITEM;
  53.     windowID[1] = ID_MENU_ITEM;
  54.     windowID[2] = ID_BUTTON;
  55.     search.type = ID_PULL_DOWN_ITEM;
  56.  
  57.     woFlags &= ~WOF_BORDER;
  58.     userFunction = UIW_PULL_DOWN_ITEM::PullDownUserFunction;
  59.     for (int i = 0; flagItem[i].string; i++)
  60.     {
  61.         UIW_POP_UP_ITEM *item = (flagItem[i].string[0] != '\0') ?
  62.             new UIW_POP_UP_ITEM(flagItem[i].string, MNIF_NO_FLAGS,
  63.                 BTF_NO_TOGGLE, WOF_NO_FLAGS, flagItem[i].userFunction) :
  64.             new UIW_POP_UP_ITEM;
  65.         item->value = flagItem[i].value;
  66.         menu.Add(item);
  67.     }
  68. }
  69.  
  70. void UIW_PULL_DOWN_ITEM::DataSet(char *newString)
  71. {
  72.     // Reset the button's string information.
  73.     if (newString)
  74.     {
  75.         if (FlagSet(woFlags, WOF_NO_ALLOCATE_DATA))
  76.             string = newString;
  77.         else
  78.         {
  79.             if (string)
  80.                 delete string;
  81.             string = (newString) ? ui_strdup(newString) : 0;
  82.         }
  83.     }
  84.     UI_WINDOW_OBJECT::Redisplay(TRUE);
  85. }
  86.  
  87. UIW_PULL_DOWN_ITEM::Event(const UI_EVENT &event)
  88. {
  89.     int ccode = event.type;
  90.     switch (ccode)
  91.     {
  92.     case S_CREATE:
  93.         menu.InformationSet(-screenID, display, eventManager, windowManager, 
  94.             paletteMapTable, this);
  95.         relative.left = relative.top = 0;
  96.         relative.right = display->TextWidth(string) - 1;
  97.         if (strchr(string, '~'))
  98.             relative.right -= display->cellWidth;
  99.         relative.bottom = display->cellHeight - 1;
  100.         if (display->isText)
  101.             woStatus &= ~WOS_GRAPHICS;
  102.         else
  103.             woStatus |= WOS_GRAPHICS;
  104.         ccode = UIW_BUTTON::Event(event);
  105.         break;
  106.  
  107.     default:
  108.         ccode = UIW_BUTTON::Event(event);
  109.         break;
  110.     }
  111.  
  112.     // Return the event control code.
  113.     return (ccode);
  114. }
  115.  
  116. void *UIW_PULL_DOWN_ITEM::Information(INFORMATION_REQUEST request, void *data)
  117. {
  118.     if (request == GET_NUMBERID_OBJECT || request == GET_STRINGID_OBJECT)
  119.         return (menu.Information(request, data));
  120.     else if (request == PRINT_INFORMATION)
  121.     {
  122.         UI_WINDOW_OBJECT::Information(request, data);
  123.         return (menu.Information(request, data));
  124.     }
  125.     else
  126.         return (UI_WINDOW_OBJECT::Information(request, data));
  127. }
  128.  
  129. #ifdef ZIL_LOAD
  130. UIW_PULL_DOWN_ITEM::UIW_PULL_DOWN_ITEM(const char *name, UI_STORAGE *file, USHORT loadFlags) :
  131.     UIW_BUTTON(name, file, loadFlags | L_SUB_LEVEL), menu(0, file, L_SUB_LEVEL)
  132. {
  133.     windowID[0] = ID_PULL_DOWN_ITEM;
  134.     windowID[1] = ID_MENU_ITEM;
  135.     windowID[2] = ID_BUTTON;
  136.  
  137.     userFunction = UIW_PULL_DOWN_ITEM::PullDownUserFunction;
  138.     if (!file)
  139.         file = _storage;
  140.     if (!FlagSet(loadFlags, L_SUB_LEVEL) && FlagSet(file->stStatus, STS_TEMPORARY))
  141.         delete file;
  142. }
  143. #endif
  144.  
  145. #ifdef ZIL_STORE
  146. void UIW_PULL_DOWN_ITEM::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
  147. {
  148.     UIW_BUTTON::Store(name, file, storeFlags | S_SUB_LEVEL);
  149.     menu.Store(0, file, S_SUB_LEVEL | S_SKIP_TYPE);
  150.     if (!FlagSet(storeFlags, S_SUB_LEVEL))
  151.         file->ObjectSize(name, search);
  152. }
  153. #endif
  154.