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 / POPUP1.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-01  |  5.3 KB  |  210 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.     if (FlagSet(mniFlags, MNIF_RESTORE))
  82.         search.numberID = NUMID_OPT_RESTORE;
  83.     else if (FlagSet(mniFlags, MNIF_MOVE))
  84.         search.numberID = NUMID_OPT_MOVE;
  85.     else if (FlagSet(mniFlags, MNIF_SIZE))
  86.         search.numberID = NUMID_OPT_SIZE;
  87.     else if (FlagSet(mniFlags, MNIF_MINIMIZE))
  88.         search.numberID = NUMID_OPT_MINIMIZE;
  89.     else if (FlagSet(mniFlags, MNIF_MAXIMIZE))
  90.         search.numberID = NUMID_OPT_MAXIMIZE;
  91.     else if (FlagSet(mniFlags, MNIF_CLOSE))
  92.         search.numberID = NUMID_OPT_CLOSE;
  93. }
  94.  
  95. UIW_POP_UP_ITEM::UIW_POP_UP_ITEM(char *_string, USHORT _mniFlags, USHORT _btFlags,
  96.     USHORT _woFlags, void (*_userFunction)(void *object, UI_EVENT &event), USHORT _value) :
  97.     UIW_BUTTON(0, 0, strlen(_string) + 2, 0, _btFlags | BTF_NO_3D, _woFlags,
  98.     _userFunction, _value), mniFlags(_mniFlags)
  99. {
  100.     UIW_POP_UP_ITEM::Initialize(_string);
  101. }
  102.  
  103. UIW_POP_UP_ITEM::UIW_POP_UP_ITEM(int left, int top, int width, char *_string,
  104.     USHORT _mniFlags, USHORT _btFlags, USHORT _woFlags,
  105.     void (*_userFunction)(void *object, UI_EVENT &event), USHORT _value) :
  106.     UIW_BUTTON(left, top, width, 0, _btFlags | BTF_NO_3D, _woFlags,
  107.     _userFunction, _value), mniFlags(_mniFlags)
  108. {
  109.     UIW_POP_UP_ITEM::Initialize(_string);
  110. }
  111.  
  112. UIW_POP_UP_ITEM::UIW_POP_UP_ITEM() :
  113.     UIW_BUTTON(0, 0, 1, "", BTF_NO_3D, WOF_NON_SELECTABLE, 0, 0)
  114. {
  115.     /* This is the constructor for a menu item seperator */
  116.     windowID[0] = ID_POP_UP_ITEM;
  117.     windowID[1] = ID_MENU_ITEM;
  118.     windowID[2] = ID_BUTTON;
  119.     search.type = ID_POP_UP_ITEM;
  120.  
  121.     mniFlags = MNIF_SEPARATOR;
  122.     woFlags &= ~WOF_BORDER;
  123.     woAdvancedFlags |= WOAF_NON_CURRENT;
  124. }
  125.  
  126. void UIW_POP_UP_ITEM::DataSet(char *newString)
  127. {
  128.     // Reset the button's string information.
  129.     if (newString)
  130.     {
  131.         if (FlagSet(woFlags, WOF_NO_ALLOCATE_DATA))
  132.             string = newString;
  133.         else
  134.         {
  135.             if (string)
  136.                 delete string;
  137.             string = new char[strlen(newString) + 3];
  138.             if (newString[0] != ' ')
  139.             {
  140.                 strcpy(string, " ");
  141.                 strcat(string, newString);
  142.                 strcat(string, " ");
  143.             }
  144.             else
  145.                 strcpy(string, newString);
  146.         }
  147.     }
  148.     UI_WINDOW_OBJECT::Redisplay(FALSE);
  149. }
  150.  
  151. UIW_POP_UP_ITEM::Event(const UI_EVENT &event)
  152. {
  153.     /* Switch on the event type */
  154.     int ccode = event.type;
  155.     switch (ccode)
  156.     {
  157.     case S_CURRENT:
  158.     case S_NON_CURRENT:
  159.     case S_DISPLAY_INACTIVE:
  160.     case S_DISPLAY_ACTIVE:
  161.         if (FlagSet(mniFlags, MNIF_SEPARATOR))
  162.         {
  163.             if (!string)
  164.                 string = ui_strdup(" ");
  165.             if (string[0] != '\0')
  166.                 string[0] = '\0';
  167.             int line = (true.top + true.bottom) / 2;
  168.             lastPalette = UI_WINDOW_OBJECT::LogicalPalette(ccode);
  169.             display->Rectangle(screenID, true, lastPalette, 0, TRUE);
  170.             display->Line(screenID, true.left, line, true.right, line, 
  171.                 MapPalette(paletteMapTable, ccode, ID_OUTLINE));
  172.             break;
  173.         }    
  174.         // Continue to default.
  175.  
  176.     default:
  177.         ccode = UIW_BUTTON::Event(event);
  178.         break;
  179.     }
  180.  
  181.     /* Return the event control code */
  182.     return (ccode);
  183. }
  184.  
  185. #ifdef ZIL_LOAD
  186. UIW_POP_UP_ITEM::UIW_POP_UP_ITEM(const char *name, UI_STORAGE *file, USHORT loadFlags) :
  187.     UIW_BUTTON(name, file, loadFlags | L_SUB_LEVEL)
  188. {
  189.     windowID[0] = ID_POP_UP_ITEM;
  190.     windowID[1] = ID_MENU_ITEM;
  191.     windowID[2] = ID_BUTTON;
  192.  
  193.     if (!file)
  194.         file = _storage;
  195.     file->Load(&mniFlags);
  196.     if (!FlagSet(loadFlags, L_SUB_LEVEL) && FlagSet(file->stStatus, STS_TEMPORARY))
  197.         delete file;
  198. }
  199. #endif
  200.  
  201. #ifdef ZIL_STORE
  202. void UIW_POP_UP_ITEM::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
  203. {
  204.     UIW_BUTTON::Store(name, file, storeFlags | S_SUB_LEVEL);
  205.     file->Store(mniFlags);
  206.     if (!FlagSet(storeFlags, S_SUB_LEVEL))
  207.         file->ObjectSize(name, search);
  208. }
  209. #endif
  210.