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

  1. //    Zinc Interface Library - POPUP1.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 <mem.h>
  7. #include <ctype.h>
  8. #include <string.h>
  9.  
  10. void UIW_POP_UP_ITEM::PopUpItemUserFunction(void *data, UI_EVENT &event)
  11. {
  12.     UIW_POP_UP_ITEM *item = (UIW_POP_UP_ITEM *)data;
  13.  
  14.     event.type = 0;
  15.     switch (item->NumberID())
  16.     {
  17.     case NUMID_OPT_RESTORE:
  18.         UI_WINDOW_OBJECT *topWindow = item->parent;
  19.         while (topWindow->parent)
  20.             topWindow = topWindow->parent;
  21.         event.type = (FlagSet(topWindow->woAdvancedStatus, WOAS_MINIMIZED)) ?
  22.             S_MINIMIZE : S_MAXIMIZE;
  23.         break;
  24.  
  25.     case NUMID_OPT_MOVE:
  26.         event.type = S_MOVE;
  27.         event.rawCode = 0xFFFF;
  28.         break;
  29.  
  30.     case NUMID_OPT_SIZE:
  31.         event.type = S_SIZE;
  32.         event.rawCode = 0xFFFF;
  33.         break;
  34.  
  35.     case NUMID_OPT_MAXIMIZE:
  36.         event.type = S_MAXIMIZE;
  37.         break;
  38.  
  39.     case NUMID_OPT_MINIMIZE:
  40.         event.type = S_MINIMIZE;
  41.         break;
  42.  
  43.     case NUMID_OPT_CLOSE:
  44.     {
  45.         UI_WINDOW_OBJECT *root = item->parent;
  46.         while (root->parent)
  47.             root = root->parent;
  48.         event.type = FlagSet(root->woAdvancedFlags, WOAF_LOCKED) ?
  49.             L_EXIT_FUNCTION : S_CLOSE;
  50.         break;
  51.     }
  52.     }
  53.     if (event.type)
  54.     {
  55.         item->eventManager->Put(event, Q_BEGIN);
  56.         event.type = S_CLOSE_TEMPORARY;
  57.         item->eventManager->Put(event, Q_BEGIN);
  58.     }
  59. }
  60.  
  61. void UIW_POP_UP_ITEM::Initialize(char *_string)
  62. {
  63.     // Initialize the menu item information.
  64.     windowID[0] = ID_POP_UP_ITEM;
  65.     windowID[1] = ID_MENU_ITEM;
  66.     windowID[2] = ID_BUTTON;
  67.     search.type = ID_POP_UP_ITEM;
  68.  
  69.     if (_string && !FlagSet(woFlags, WOF_NO_ALLOCATE_DATA))
  70.     {
  71.         string = new char[strlen(_string) + 3];
  72.         strcpy(string, " ");
  73.         strcat(string, _string);
  74.         strcat(string, " ");
  75.     }
  76.     else if (_string)
  77.         string = _string;
  78.     else
  79.         string = NULL;
  80.  
  81.     woFlags &= ~WOF_BORDER;
  82.  
  83.     if (FlagSet(mniFlags, MNIF_RESTORE))
  84.         search.numberID = NUMID_OPT_RESTORE;
  85.     else if (FlagSet(mniFlags, MNIF_MOVE))
  86.         search.numberID = NUMID_OPT_MOVE;
  87.     else if (FlagSet(mniFlags, MNIF_SIZE))
  88.         search.numberID = NUMID_OPT_SIZE;
  89.     else if (FlagSet(mniFlags, MNIF_MINIMIZE))
  90.         search.numberID = NUMID_OPT_MINIMIZE;
  91.     else if (FlagSet(mniFlags, MNIF_MAXIMIZE))
  92.         search.numberID = NUMID_OPT_MAXIMIZE;
  93.     else if (FlagSet(mniFlags, MNIF_CLOSE))
  94.         search.numberID = NUMID_OPT_CLOSE;
  95. }
  96.  
  97. UIW_POP_UP_ITEM::UIW_POP_UP_ITEM(char *_string, USHORT _mniFlags, USHORT _btFlags,
  98.     USHORT _woFlags, void (*_userFunction)(void *object, UI_EVENT &event), USHORT _value) :
  99.     UIW_BUTTON(0, 0, strlen(_string) + 2, NULL, _btFlags | BTF_NO_3D, _woFlags,
  100.     _userFunction, _value), mniFlags(_mniFlags)
  101. {
  102.     UIW_POP_UP_ITEM::Initialize(_string);
  103. }
  104.  
  105. UIW_POP_UP_ITEM::UIW_POP_UP_ITEM(int left, int top, int width, char *_string,
  106.     USHORT _mniFlags, USHORT _btFlags, USHORT _woFlags,
  107.     void (*_userFunction)(void *object, UI_EVENT &event), USHORT _value) :
  108.     UIW_BUTTON(left, top, width, NULL, _btFlags | BTF_NO_3D, _woFlags,
  109.     _userFunction, _value), mniFlags(_mniFlags)
  110. {
  111.     UIW_POP_UP_ITEM::Initialize(_string);
  112. }
  113.  
  114. UIW_POP_UP_ITEM::UIW_POP_UP_ITEM() :
  115.     UIW_BUTTON(0, 0, 1, "", BTF_NO_3D, WOF_NON_SELECTABLE, 0, 0)
  116. {
  117.     // This is the constructor for a menu item seperator.
  118.     windowID[0] = ID_POP_UP_ITEM;
  119.     windowID[1] = ID_MENU_ITEM;
  120.     windowID[2] = ID_BUTTON;
  121.     search.type = ID_POP_UP_ITEM;
  122.  
  123.     mniFlags = MNIF_SEPARATOR;
  124.     woFlags &= ~WOF_BORDER;
  125.     woAdvancedFlags |= WOAF_NON_CURRENT;
  126. }
  127.  
  128. void UIW_POP_UP_ITEM::DataSet(char *newString)
  129. {
  130.     // Reset the button's string information.
  131.     if (newString)
  132.     {
  133.         if (FlagSet(woFlags, WOF_NO_ALLOCATE_DATA))
  134.             string = newString;
  135.         else
  136.         {
  137.             if (string)
  138.                 delete string;
  139.             string = new char[strlen(newString) + 3];
  140.             strcpy(string, " ");
  141.             strcat(string, newString);
  142.             strcat(string, " ");
  143.         }
  144.     }
  145.     if (!string || string[0] == '\0')
  146.     {
  147.         mniFlags = MNIF_SEPARATOR;
  148.         woAdvancedFlags |= WOAF_NON_CURRENT;
  149.     }
  150.     else
  151.     {
  152.         mniFlags &= ~MNIF_SEPARATOR;
  153.         woAdvancedFlags &= ~WOAF_NON_CURRENT;
  154.     }
  155.  
  156.     if (hMenu)
  157.     {
  158.         UIW_POP_UP_ITEM *item = this;
  159.         for (int count = 0; item; item->Previous())
  160.             count++;
  161.         if (FlagSet(mniFlags, MNIF_SEPARATOR))
  162.             ModifyMenu(hMenu, MF_BYCOMMAND, MF_SEPARATOR, count, NULL);
  163.         else
  164.             ModifyMenu(hMenu, MF_BYCOMMAND, MF_STRING, count, string);
  165.         DrawMenuBar(screenID);
  166.     }
  167.     else
  168.     {
  169.         if (parent)
  170.             parent->Redisplay(TRUE);
  171.         else
  172.             UI_WINDOW_OBJECT::Redisplay(TRUE);
  173.     }
  174. }
  175.  
  176. UIW_POP_UP_ITEM::Event(const UI_EVENT &event)
  177. {
  178.     // Switch on the event type.
  179.     int ccode = event.type;
  180.  
  181.     switch (ccode)
  182.     {
  183.     case S_INITIALIZE:
  184.         {
  185.         // Add item - event.rawCode ID number.
  186.         char *tHotKey = NULL;
  187.         if (string)
  188.             tHotKey = strchr(string, '~');
  189.         if (tHotKey)
  190.             hotKey = toupper(tHotKey[1]);
  191.         if (string && (hMenu || FlagSet(btFlags, BTF_NO_3D)))
  192.             ui_strrepc(string, '~', '&');
  193.         }
  194.         break;
  195.  
  196.     case S_CURRENT:
  197.     case S_DISPLAY_INACTIVE:
  198.     case S_DISPLAY_ACTIVE:
  199.         if (hMenu)
  200.             HiliteMenuItem(screenID, hMenu, 0, MF_BYPOSITION | MF_HILITE);
  201.         else if (FlagSet(mniFlags, MNIF_SEPARATOR))
  202.         {
  203.             lastPalette = 0;
  204.             ccode = UIW_BUTTON::Event(event);
  205.             int line = (true.top + true.bottom) / 2;
  206.             display->Line(screenID, true.left, line, true.right, line, 
  207.                 MapPalette(paletteMapTable, ccode, ID_OUTLINE));
  208.             break;
  209.         }    
  210.         // Continue to default.
  211.  
  212.     default:
  213.         ccode = UIW_BUTTON::Event(event);
  214.         break;
  215.     }
  216.  
  217.     // Return the event control code.
  218.     return (ccode);
  219. }
  220.  
  221. #ifdef ZIL_LOAD
  222. UIW_POP_UP_ITEM::UIW_POP_UP_ITEM(const char *name, UI_STORAGE *file, USHORT loadFlags) :
  223.     UIW_BUTTON(name, file, loadFlags | L_SUB_LEVEL)
  224. {
  225.     windowID[0] = ID_POP_UP_ITEM;
  226.     windowID[1] = ID_MENU_ITEM;
  227.     windowID[2] = ID_BUTTON;
  228.  
  229.     if (!file)
  230.         file = _storage;
  231.     file->Load(&mniFlags);
  232.     if (!FlagSet(loadFlags, L_SUB_LEVEL) && FlagSet(file->stStatus, STS_TEMPORARY))
  233.         delete file;
  234. }
  235. #endif
  236.  
  237. #ifdef ZIL_STORE
  238. void UIW_POP_UP_ITEM::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
  239. {
  240.     UIW_BUTTON::Store(name, file, storeFlags | S_SUB_LEVEL);
  241.     file->Store(mniFlags);
  242.     if (!FlagSet(storeFlags, S_SUB_LEVEL))
  243.         file->ObjectSize(name, search);
  244. }
  245. #endif
  246.