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

  1. //    Zinc Interface Library - WINDOW2.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 <io.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. USHORT UI_WINDOW_OBJECT::NumberID(USHORT numberID)
  11. {
  12.     if (numberID)
  13.         search.numberID = numberID;
  14.     return (search.numberID);
  15. }
  16.  
  17. char *UI_WINDOW_OBJECT::StringID(const char *stringID)
  18. {
  19.     if (stringID)
  20.         strcpy(search.stringID, stringID);
  21.     return (search.stringID);
  22. }
  23.  
  24. UI_WINDOW_OBJECT::UI_WINDOW_OBJECT(int left, int top, int width, int height,
  25.     USHORT _woFlags, USHORT _woAdvancedFlags) : woFlags(_woFlags),
  26.     woAdvancedFlags(_woAdvancedFlags), woStatus(WOS_NO_STATUS),
  27.     woAdvancedStatus(WOAS_INVALID_REGION), parent(0), display(0), eventManager(0),
  28.     windowManager(0), paletteMapTable(_normalPaletteMapTable),
  29.     lastPalette(&paletteMapTable[0].palette), Validate(0), hotKey(0),
  30.     screenID(-1), userObject(NULL), userFlags(0), helpContext(NO_HELP_CONTEXT)
  31. {
  32.     // Intialize the screen object information.
  33.     hWnd = 0;
  34.     hMenu = 0;
  35.     screenID = 0;
  36.     MSWindowsStyle = 0;
  37.  
  38.     windowID[0] = windowID[1] = windowID[2] = windowID[3] = windowID[4] = ID_WINDOW_OBJECT;
  39.  
  40.     if (FlagSet(_woFlags, WOF_UNANSWERED))
  41.         woStatus |= WOS_UNANSWERED;
  42.     if (FlagSet(_woFlags, WOF_INVALID))
  43.         woStatus |= WOS_INVALID;
  44.     
  45.     true.left = relative.left = left;
  46.     true.top = relative.top = top;
  47.     true.right = relative.right = (left >= 0 && width > 0) ?
  48.         left + width - 1 : width;
  49.     true.bottom = relative.bottom = (top >= 0 && height > 0) ?
  50.         top + height - 1 : height;
  51.  
  52.     search.stringID[0] = '\0';
  53.     search.numberID = search.type = search.size = 0;
  54.     search.offset = 0L;
  55.  
  56.     // Match with the appropriate Windows 3.0 flags.
  57.     if (FlagSet(woFlags, WOF_BORDER))
  58.         MSWindowsStyle |= WS_BORDER;
  59. }
  60.  
  61. UI_WINDOW_OBJECT::~UI_WINDOW_OBJECT(void)
  62. {
  63.     if (hWnd && !parent)
  64.     {
  65.         SetWindowExtra(hWnd, 0, 0L);
  66.         DestroyWindow(hWnd);
  67.         hWnd = 0;
  68.         hMenu = 0;
  69.         screenID = 0;
  70.     }
  71. }
  72.  
  73. void UI_WINDOW_OBJECT::Border(int ccode, UI_REGION ®ion,
  74.     const UI_PALETTE *palette)
  75. {
  76.     // Compute the display region.
  77.     region = true;
  78.  
  79.     // Make sure the object needs a border.
  80.     if (!FlagSet(woFlags, WOF_BORDER))
  81.         return;
  82.  
  83.     // DeterMine the border and update the region.
  84.     int displayBorder = (ccode == S_DISPLAY_ACTIVE || 
  85.         ccode == S_NON_CURRENT || ccode == S_DISPLAY_INACTIVE ||
  86.         ccode == S_CURRENT) ? TRUE : FALSE;
  87.     int logicalPalette;
  88.     if (FlagSet(woAdvancedStatus, WOAS_TOO_SMALL) || FlagSet(woFlags, WOF_VIEW_ONLY))
  89.         logicalPalette = PM_VIEW;
  90.     else if (ccode == S_DISPLAY_INACTIVE)
  91.         logicalPalette = PM_INACTIVE;
  92.     else
  93.         logicalPalette = PM_ACTIVE;
  94.     UI_PALETTE *outlinePalette = MapPalette(paletteMapTable, logicalPalette,
  95.         ID_OUTLINE);
  96.     if (display->isText && (region.top == region.bottom))
  97.     {
  98.         if (region.left <= region.right - 2 * display->cellWidth)
  99.         {
  100.             if (displayBorder)
  101.                 display->Text(screenID, region.left, region.top, "[", outlinePalette, 1);
  102.             region.left++;
  103.         }
  104.         if (region.left <= region.right - display->cellWidth)
  105.         {
  106.             if (displayBorder)
  107.                 display->Text(screenID, region.right, region.top, "]", outlinePalette, 1);
  108.             region.right--;
  109.         }
  110.     }
  111.     if (region.top + 1 >= region.bottom || region.left + 1 >= region.right)
  112.         return;
  113.     if (displayBorder)
  114.         display->Rectangle(screenID, region, outlinePalette);
  115.     region.left++;
  116.     region.top++;
  117.     region.right--;
  118.     region.bottom--;
  119.     if (FlagSet(woFlags, WOF_NON_FIELD_REGION) || ccode == S_CREATE ||
  120.         display->isText)
  121.         return;
  122.  
  123.     if (region.top + 1 >= region.bottom || region.left + 1 >= region.right)
  124.         return;
  125.     if (displayBorder && palette)
  126.         display->Rectangle(screenID, region, palette);
  127.     region.left++;
  128.     region.top++;
  129.     region.right--;
  130.     region.bottom--;
  131.     if (region.left + 1 >= region.right)
  132.         return;
  133.     if (displayBorder && palette)
  134.     {
  135.         display->Line(screenID, region.left, region.top, region.left, region.bottom, palette);
  136.         display->Line(screenID, region.right, region.top, region.right, region.bottom, palette);
  137.     }
  138.     region.left++;
  139.     region.right--;
  140. }
  141.         
  142. int UI_WINDOW_OBJECT::Event(const UI_EVENT &event)
  143. {
  144.     // Switch on the event type.
  145.     int ccode = UI_WINDOW_OBJECT::LogicalEvent(event, ID_WINDOW_OBJECT);
  146.     switch (ccode)
  147.     {
  148.     case S_CREATE:
  149.     case S_SIZE:
  150.         display->RegionConvert(relative, &woStatus, WOS_GRAPHICS);
  151.         if (!display->isText && relative.bottom == relative.top)
  152.             relative.bottom += display->cellHeight - 1;
  153.         UI_WINDOW_OBJECT::RegionMax(TRUE);
  154.         break;
  155.  
  156.     case S_MOVE:
  157.         if (!parent || FlagSet(woAdvancedFlags, WOAF_TEMPORARY) ||
  158.             FlagSet(woAdvancedStatus, WOAS_INVALID_REGION))
  159.             break;
  160.         true.left += event.position.column;
  161.         true.top += event.position.line;
  162.         true.right += event.position.column;
  163.         true.bottom += event.position.line;
  164.         UI_REGION region = parent->true;
  165.         if (true.left < region.left || true.top < region.top ||
  166.             true.right > region.right || true.bottom > region.bottom)
  167.             woAdvancedStatus |= WOAS_INVALID_REGION;
  168.         else
  169.             woAdvancedStatus &= ~WOAS_INVALID_REGION;
  170.         break;
  171.  
  172.     case L_VIEW:
  173.         {
  174.         UI_EVENT t_event = event;
  175.         t_event.rawCode = DM_VIEW;
  176.         eventManager->Event(t_event);
  177.         }
  178.         break;
  179.  
  180.     case L_SELECT:
  181.         {
  182.         UI_EVENT t_event = event;
  183.         t_event.type = L_NEXT;
  184.         eventManager->Event(t_event);
  185.         }
  186.  
  187.     default:
  188.         ccode = S_UNKNOWN;
  189.         break;
  190.     }
  191.  
  192.     return (ccode);
  193. }
  194.  
  195. void *UI_WINDOW_OBJECT::Information(INFORMATION_REQUEST request, void *data)
  196. {
  197.     // Switch on the request type.
  198.     switch(request)
  199.     {
  200.     case GET_MINIMUM_WIDTH:
  201.         *(int *)data = (display->isText) ? 2 : display->cellWidth * 2 - 1;
  202.         break;
  203.  
  204.     case GET_MINIMUM_HEIGHT:
  205.         *(int *)data = (display->isText) ? 1 : display->cellHeight - 1;
  206.         break;
  207.  
  208.     case GET_DEFAULT_HEIGHT:
  209.         *(int *)data = (display->isText) ? display->cellHeight : 16;
  210.         break;
  211.  
  212.     case GET_DEFAULT_WIDTH:
  213.         *(int *)data = (display->isText) ? display->cellWidth : 32;
  214.         break;
  215.  
  216. #ifdef ZIL_STORE
  217.         case PRINT_INFORMATION:
  218.             {
  219.             if (search.stringID[0] == '\0' || search.numberID > 0xFF00)
  220.                 break;
  221.             char buffer[128];
  222.             sprintf(buffer, "#define %-32s 0x%04X\r\n", search.stringID, search.numberID);
  223.             _write(*(int *)data, buffer, strlen(buffer));
  224.             break;
  225.             }
  226. #endif
  227.  
  228.     default:
  229.         data = NULL;
  230.         break;
  231.     }
  232.  
  233.     return (data);
  234. }
  235.  
  236. #pragma argsused
  237. UI_WINDOW_OBJECT::NeedsUpdate(const UI_EVENT &event, int ccode)
  238. {
  239.     UI_PALETTE *palette = UI_WINDOW_OBJECT::LogicalPalette(ccode);
  240.     if ((palette == lastPalette && !FlagSet(woAdvancedFlags, WOAF_OUTSIDE_REGION) && 
  241.          !UI_WINDOW_OBJECT::Overlap(event.region)) ||
  242.         (palette == lastPalette && FlagSet(woAdvancedFlags, WOAF_OUTSIDE_REGION) && 
  243.          !parent->Overlap(event.region)))
  244.         return (FALSE);
  245.     lastPalette = palette;
  246.     return(TRUE);
  247. }
  248.  
  249. #pragma argsused
  250. int UI_WINDOW_OBJECT::NeedsValidation(void)
  251. {
  252.     int needsValidation = 
  253.         (Validate && !FlagSet(woStatus, WOS_UNANSWERED) &&
  254.         FlagSet(woAdvancedStatus, WOAS_NEED_VALIDATE)) ? TRUE : FALSE;
  255.     woAdvancedStatus &= ~WOAS_NEED_VALIDATE;
  256.     return (needsValidation);
  257. }
  258.  
  259. #pragma argsused
  260. int UI_WINDOW_OBJECT::Overlap(const UI_REGION ®ion)
  261. {
  262.     return (Max(region.left, true.left) <= Min(region.right, true.right) &&
  263.         Max(region.top, true.top) <= Min(region.bottom, true.bottom));
  264. }
  265.  
  266. #pragma argsused
  267. void UI_WINDOW_OBJECT::RegionMax(int leftTop)
  268. {
  269.     UI_REGION_LIST regionList;
  270.     UI_REGION_ELEMENT *dRegion;
  271.     UI_WINDOW_OBJECT *object;
  272.     UI_REGION region;
  273.  
  274.     // Make sure the object has a parent.
  275.     if (!parent || FlagSet(woAdvancedFlags, WOAF_TEMPORARY))
  276.     {
  277.         woAdvancedStatus &= ~WOAS_INVALID_REGION;
  278.         true = relative;
  279.         return;
  280.     }
  281.  
  282.     // Compute the update regions then make an update request.
  283.     region = parent->true;
  284.     parent->Border(S_CREATE, region, 0);
  285.     regionList.Add(0, new UI_REGION_ELEMENT(screenID, ®ion));
  286.     /* Get the first object */
  287.     for (object = this; object->previous; object = object->Previous())
  288.         ;
  289.     for (; object && object != this; object = object->Next())
  290.     {
  291.         if (FlagSet(object->woAdvancedFlags, WOAF_OUTSIDE_REGION))
  292.         {
  293.             regionList.Destroy();
  294.             regionList.Add(0, new UI_REGION_ELEMENT(screenID,
  295.                 object->true.left + 1, object->true.top + 1,
  296.                 object->true.right - 1, object->true.bottom - 1));
  297.         }
  298.         else if (FlagSet(object->woFlags, WOF_NON_FIELD_REGION) &&
  299.             !FlagSet(object->woAdvancedStatus, WOAS_INVALID_REGION))
  300.             regionList.Split(screenID, object->true);
  301.     }
  302.  
  303.     // Get the region then destroy the region list.
  304.     if (leftTop)
  305.     {
  306.         region.left = parent->true.right + 1;
  307.         region.top = parent->true.bottom + 1;
  308.         region.right = region.left - 1;
  309.         region.bottom = region.top - 1;
  310.         for (dRegion = regionList.First(); dRegion; dRegion = dRegion->Next())
  311.             if (dRegion->region.top <= region.top &&
  312.                 (!FlagSet(woFlags, WOF_NON_FIELD_REGION) ||
  313.                  dRegion->region.right - dRegion->region.left >=
  314.                  relative.right - relative.left))
  315.                 region = dRegion->region;
  316.     }
  317.     else
  318.     {
  319.         region.right = parent->true.left;
  320.         region.bottom = parent->true.top;
  321.         region.left = region.right + 1;
  322.         region.top = region.bottom + 1;
  323.         for (dRegion = regionList.First(); dRegion; dRegion = dRegion->Next())
  324.             if (dRegion->region.bottom >= region.bottom &&
  325.                 (!FlagSet(woFlags, WOF_NON_FIELD_REGION) ||
  326.                  dRegion->region.right - dRegion->region.left >=
  327.                  relative.right - relative.left))
  328.                 region = dRegion->region;
  329.     }
  330.  
  331.     // Compute relative coordinates.
  332.     if (!FlagSet(woFlags, WOF_NON_FIELD_REGION))
  333.     {
  334.         if (relative.left < 0 || relative.top < 0)
  335.         {
  336.             woAdvancedStatus |= WOAS_INVALID_REGION;
  337.             return;
  338.         }
  339.         true.left = region.left + relative.left;
  340.         true.top = region.top + relative.top;
  341.         true.right = region.left + relative.right;
  342.         true.bottom = region.top + relative.bottom;
  343.         woAdvancedStatus &= ~WOAS_TOO_SMALL;
  344.         if (true.right > region.right)
  345.         {
  346.             if (true.right > region.right + 2)
  347.                 woAdvancedStatus |= WOAS_TOO_SMALL;
  348.             true.right = region.right;
  349.         }
  350.         if (true.bottom > region.bottom)
  351.         {
  352.             if (true.bottom > region.bottom + 2)
  353.                 woAdvancedStatus |= WOAS_TOO_SMALL;
  354.             true.bottom = region.bottom;
  355.         }
  356.     }
  357.     else
  358.         true = region;
  359.  
  360.     // Check for the validity of the region.
  361.     if (true.left > true.right || true.top > true.bottom ||
  362.         true.left < parent->true.left || true.top < parent->true.top)
  363.         woAdvancedStatus |= WOAS_INVALID_REGION;
  364.     else
  365.         woAdvancedStatus &= ~WOAS_INVALID_REGION;
  366.     if (FlagSet(woAdvancedStatus, WOAS_INVALID_REGION | WOAS_TOO_SMALL))
  367.         woStatus &= ~WOS_CURRENT;
  368. }
  369.  
  370. #pragma argsused
  371. void UI_WINDOW_OBJECT::Redisplay(int fromRoot)
  372. {
  373.     // Preserve the original region for re-display.
  374.     UI_EVENT event;
  375.     event.region = true;
  376.  
  377.     // Find the root then make sure the window manager is attached.
  378.     UI_WINDOW_OBJECT *root = this;
  379.     while (root->parent)
  380.         root = root->parent;
  381.     if (FlagSet(root->woAdvancedStatus, WOAS_REDISPLAY) ||
  382.         !display || !eventManager || !windowManager)
  383.         fromRoot = TRUE;
  384.     if (!root->display || !root->eventManager || !root->windowManager)
  385.     {
  386.         root->woAdvancedStatus |= WOAS_REDISPLAY;
  387.         return;
  388.     }
  389.  
  390.     // Redisplay the window by sending a create, then redisplay message.
  391.     event.type = S_CREATE;
  392.     if (fromRoot)
  393.         root->Event(event);
  394.     else
  395.         Event(event);
  396.     event.type = (root == windowManager->First()) ?
  397.         S_DISPLAY_ACTIVE : S_DISPLAY_INACTIVE;
  398.     if (fromRoot)
  399.         root->Event(event);
  400.     else
  401.         Event(event);
  402. }
  403.  
  404. #pragma argsused
  405. void UI_WINDOW_OBJECT::Shadow(UI_REGION ®ion, int depth)
  406. {
  407.     // Make sure the region is large enough to shadow.
  408.     if (depth == 0)
  409.         return;
  410.     int left, top, right, bottom;
  411.     UI_REGION tRegion;
  412.     tRegion = region;
  413.     left = region.left + 1;
  414.     top = region.top + 1;
  415.     right = region.right - 2;
  416.     bottom = region.bottom - 2;
  417.     if (left + depth > right || top + depth > bottom)
  418.     {
  419.         region = true;
  420.         region.left += 1;
  421.         region.top += 1;
  422.         region.right -= 1;
  423.         region.bottom -= 1;
  424.     }
  425.  
  426.     // Hide the screen devices.
  427.     if (eventManager)
  428.         eventManager->DevicesHide(tRegion);
  429.  
  430.     // Left column and top lines.
  431.     UI_PALETTE *palette = MapPalette(paletteMapTable, PM_ANY,
  432.         (depth > 0) ? ID_WHITE_SHADOW : ID_LIGHT_SHADOW);
  433.     display->Line(screenID, left, top, left, bottom, palette);
  434.     display->Line(screenID, left, top, right--, top, palette);
  435.     top++;
  436.     if (depth == 2 || depth == -2)
  437.         display->Line(screenID, left, top, right++, top, palette);
  438.     else
  439.         right++;
  440.  
  441.     // Right columns and bottom line.
  442.     palette = MapPalette(paletteMapTable, PM_ANY,
  443.         (depth > 0) ? ID_LIGHT_SHADOW : ID_DARK_SHADOW);
  444.     top--;
  445.     bottom++;
  446.     right++;
  447.     display->Line(screenID, right, top, right, bottom, palette);
  448.     display->Line(screenID, left, bottom, right, bottom, palette);
  449.  
  450.     // Show the screen devices.
  451.     if (eventManager)
  452.         eventManager->DevicesShow(tRegion);
  453.  
  454.     // Compute the new region coordinates.
  455.     tRegion = region;
  456.     region.left = tRegion.left + 2;
  457.     region.bottom = tRegion.bottom - 2;
  458.     region.top = tRegion.top + 2;
  459.     region.right = tRegion.right - 2;
  460. }
  461.  
  462. #pragma argsused
  463. void UI_WINDOW_OBJECT::Text(char *string, int depth, int ccode,
  464.     const UI_PALETTE *palette)
  465. {
  466.     // Shadow the region if needed.
  467.     if (!display)
  468.         return;
  469.     UI_REGION region;
  470.     if (depth != 0 && !display->isText)
  471.     {
  472.         UI_WINDOW_OBJECT::Border(ccode, region, 0);
  473.         if (region.top + 2 >= region.bottom || region.left + 2 >= region.right)
  474.         {
  475.             display->Rectangle(screenID, region, palette, 0, TRUE);
  476.             return;
  477.         }
  478.         region = true;
  479.         UI_WINDOW_OBJECT::Shadow(region, depth);
  480.         display->Rectangle(screenID, region, palette, 0, TRUE);
  481.         if (!FlagSet(woFlags, WOF_JUSTIFY_RIGHT | WOF_JUSTIFY_CENTER))
  482.             region.left += depth;
  483.     }
  484.     else
  485.     {
  486.         UI_WINDOW_OBJECT::Border(ccode, region, palette);
  487.         display->Rectangle(screenID, region, palette, 0, TRUE);
  488.     }
  489.  
  490.     // Make sure it is a valid string.
  491.     if (string == 0 || string[0] == '\0')
  492.         return;
  493.  
  494.     // See if the string will fit.
  495.     int height = display->TextHeight(string, screenID) - 3;
  496.     if (region.bottom - region.top + 1 < height)
  497.         return;
  498.  
  499.     char scrapBuffer[128];
  500.     strncpy(scrapBuffer, string, 128);
  501.     char *hotKey = strchr(scrapBuffer, '~');
  502.     if (hotKey)
  503.         strcpy(hotKey, hotKey + 1);
  504.  
  505.     int width = display->TextWidth(scrapBuffer, screenID);
  506.     if (width > region.right - region.left + 1)
  507.     {
  508.         width = region.right - region.left;
  509.         scrapBuffer[width / display->cellWidth] = '\0';
  510.     }
  511.  
  512.     region.top += (region.bottom - region.top + 1 - height) / 2;
  513.     if (FlagSet(woFlags, WOF_JUSTIFY_CENTER))
  514.         region.left += (region.right - region.left + 1 - width) / 2;
  515.     else if (FlagSet(woFlags, WOF_JUSTIFY_RIGHT))
  516.         region.left = region.right - width + 1;
  517.  
  518.     display->Text(screenID, region.left, region.top, scrapBuffer, palette, -1, FALSE);
  519.  
  520.     if (!hotKey)
  521.         return;
  522.     hotKey[1] = '\0';
  523.     region.left += display->TextWidth(scrapBuffer, screenID);
  524.     if (region.left > region.right - display->TextWidth("X", screenID))
  525.         return;
  526.     if (!display->isText)
  527.     {
  528.         region.top += display->TextHeight("_", screenID);
  529.         scrapBuffer[0] = hotKey[0];
  530.         scrapBuffer[1] = '\0';
  531.         region.right = region.left;
  532.         region.left -= display->TextWidth(scrapBuffer, screenID) - 1;
  533.         display->Line(screenID, region.left, region.top, region.right,
  534.             region.top, palette);
  535.     }
  536.     else if (!FlagSet(woFlags, WOF_NON_SELECTABLE) &&
  537.         (!FlagSet(woStatus, WOS_CURRENT) || ccode == S_DISPLAY_INACTIVE))
  538.     {
  539.         palette = MapPalette(paletteMapTable, PM_HOT_KEY);
  540.         display->Text(screenID, region.left, region.top, hotKey, palette, 1, FALSE);
  541.     }
  542. }
  543.  
  544. #pragma argsused
  545. void UI_WINDOW_OBJECT::InformationSet(SCREENID _screenID, UI_DISPLAY *_display,
  546.     UI_EVENT_MANAGER *_eventManager, UI_WINDOW_MANAGER *_windowManager,
  547.     UI_PALETTE_MAP *_paletteMapTable, UI_WINDOW_OBJECT *_parent)
  548. {
  549.     // Make screenID the MS Windows handle of the current or parent window.
  550.     screenID = _screenID;
  551.  
  552.     // Set other default information.
  553.     display = _display;
  554.     eventManager = _eventManager;
  555.     windowManager = _windowManager;
  556.     if (paletteMapTable == _normalPaletteMapTable)
  557.         paletteMapTable = _paletteMapTable;
  558.     lastPalette = &paletteMapTable[0].palette;
  559.     parent = _parent;
  560. }
  561.  
  562. #pragma argsused
  563. UI_PALETTE *UI_WINDOW_OBJECT::LogicalPalette(int ccode)
  564. {
  565.     USHORT logicalPalette = PM_ACTIVE;
  566.     if (FlagSet(woFlags, WOF_NON_SELECTABLE))
  567.         logicalPalette = PM_NON_SELECTABLE;
  568.     else if (FlagSet(woAdvancedStatus, WOAS_TOO_SMALL) || FlagSet(woFlags, WOF_VIEW_ONLY))
  569.         logicalPalette = PM_VIEW;
  570.     else if (ccode == S_DISPLAY_INACTIVE)
  571.         logicalPalette = PM_INACTIVE;
  572.     else if (ccode == S_NON_CURRENT && FlagSet(woStatus, WOS_SELECTED))
  573.         logicalPalette = PM_SELECTED;
  574.     else if (ccode == S_NON_CURRENT)
  575.         logicalPalette = PM_ACTIVE;
  576.     else if (FlagSet(woStatus, WOS_CURRENT) &&
  577.         (!parent || FlagSet(parent->woStatus, WOS_CURRENT)))
  578.         logicalPalette = PM_CURRENT;
  579.     else if (FlagSet(woStatus, WOS_SELECTED))
  580.         logicalPalette = PM_SELECTED;
  581.  
  582.     return (MapPalette(paletteMapTable, logicalPalette, windowID[0],
  583.         windowID[1], windowID[2], windowID[3]));
  584. }
  585.  
  586. #ifdef ZIL_LOAD
  587. #pragma argsused
  588. UI_WINDOW_OBJECT::UI_WINDOW_OBJECT(const char *name, UI_STORAGE *file, USHORT loadFlags) :
  589.     parent(0), display(0), eventManager(0), windowManager(0),
  590.     paletteMapTable(_normalPaletteMapTable),
  591.     lastPalette(&paletteMapTable[0].palette), Validate(0), hotKey(0),
  592.     screenID(-1), woStatus(WOS_NO_STATUS), woAdvancedStatus(WOAS_NO_STATUS)
  593. {
  594.     if (!file)
  595.     {
  596.         char pathName[64], fileName[32], objectName[32];
  597.         UI_STORAGE::StripFullPath(name, pathName, fileName, objectName);
  598.         UI_STORAGE::AppendFullPath(pathName, pathName, fileName);
  599.         UI_STORAGE::ChangeExtension(pathName, ".DAT");
  600.         file = _storage = new UI_STORAGE(pathName, TRUE);
  601.         file->stStatus |= STS_TEMPORARY;
  602.         UI_STORAGE_ELEMENT *element = file->Seek(objectName, SEEK_READ);
  603.         search = element->search;
  604.     }
  605.     else if (name)
  606.     {
  607.         UI_STORAGE_ELEMENT *element = file->Seek(name, SEEK_READ);
  608.         search = element->search;
  609.     }
  610.  
  611.     windowID[0] = windowID[1] = windowID[2] = windowID[3] = ID_WINDOW_OBJECT;
  612.     file->Load(&search, sizeof(search));
  613.     file->Load(&woFlags);
  614.     file->Load(&woAdvancedFlags);
  615.     file->Load(&relative, sizeof(relative));
  616.     file->Load(&helpContext);
  617.     true = relative;
  618. }
  619. #endif
  620.  
  621. #ifdef ZIL_STORE
  622. #pragma argsused
  623. void UI_WINDOW_OBJECT::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
  624. {
  625.     if (!file)
  626.     {
  627.         char pathName[64], fileName[32], objectName[32];
  628.         UI_STORAGE::StripFullPath(name, pathName, fileName, objectName);
  629.         UI_STORAGE::AppendFullPath(pathName, pathName, fileName);
  630.         UI_STORAGE::ChangeExtension(pathName, ".DAT");
  631.         file = _storage = new UI_STORAGE(pathName, TRUE);
  632.         file->stStatus |= STS_TEMPORARY;
  633.         if (objectName[0] == '\0' && search.stringID[0] == '\0')
  634.         {
  635.             strcpy(objectName, "RESOURCE_1");
  636.             for (int i = 2; file->Seek(objectName, SEEK_READ); i++)
  637.                 sprintf(objectName, "RESOURCE_%d", i++);
  638.             search.numberID = i;
  639.         }
  640.         else if (objectName[0] == '\0')
  641.             strcpy(objectName, search.stringID);
  642.         UI_STORAGE_ELEMENT *element = file->Seek(objectName, SEEK_WRITE);
  643.         element->search.type = windowID[0];
  644.         element->search.numberID = search.numberID;
  645.         strcpy(search.stringID, objectName);
  646.         search.offset = element->search.offset;
  647.         search.size = element->search.size;
  648.     }
  649.     else if (name)
  650.     {
  651.         UI_STORAGE_ELEMENT *element = file->Seek(name, SEEK_WRITE);
  652.         element->search.type = windowID[0];
  653.         element->search.numberID = search.numberID;
  654.         strcpy(search.stringID, name);
  655.         search.offset = element->search.offset;
  656.         search.size = element->search.size;
  657.     }
  658.     else if (!FlagSet(storeFlags, S_SKIP_TYPE))
  659.         file->Store(search.type);
  660.  
  661.     file->Store(&search, sizeof(search));
  662.     file->Store(woFlags);
  663.     file->Store(woAdvancedFlags);
  664.     if (!parent)
  665.         relative = true;
  666.     UI_REGION region = relative;
  667.     if (display && !display->isText)
  668.     {
  669.         region.left /= display->cellWidth;
  670.         region.top /= display->cellHeight;
  671.         region.right /= display->cellWidth;
  672.         region.bottom /= display->cellHeight;
  673.     }
  674.     file->Store(®ion, sizeof(region));
  675.     file->Store(helpContext);
  676. }
  677. #endif
  678.