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

  1. //    Zinc Interface Library - SCROLL.CPP
  2. //    COPYRIGHT (C) 1990, 1991.  All Rights Reserved.
  3. //    Zinc Software Incorporated.  Pleasant Grove, Utah  USA
  4.  
  5. #include "ui_win.hpp"
  6.  
  7. // Special button identifications - order is important.
  8. const int TOTAL_BUTTONS        = 5;
  9. const int TOP_BUTTON        = 0;
  10. const int LEFT_BUTTON        = 0;
  11. const int BOTTOM_BUTTON        = 1;
  12. const int RIGHT_BUTTON        = 1;
  13. const int MIDDLE_BUTTON        = 2;
  14. const int TOP_REGION        = 3;
  15. const int LEFT_REGION        = 3;
  16. const int BOTTOM_REGION        = 4;
  17. const int RIGHT_REGION        = 4;
  18.  
  19. #pragma argsused
  20. void UIW_SCROLL_BAR::UserFunction(void *data, UI_EVENT &event)
  21. {
  22. }
  23.  
  24. UIW_SCROLL_BAR::UIW_SCROLL_BAR(int left, int top, int width, int height,
  25.     USHORT _sbFlags, USHORT _woFlags) :
  26.     UIW_WINDOW(left, top, width, height, _woFlags, WOAF_NON_CURRENT),
  27.     sbFlags(_sbFlags), current(0), showing(0), maximum(0)
  28. {
  29.     // Initialize the slide information.
  30.     windowID[0] = ID_SCROLL_BAR;
  31.     windowID[1] = ID_WINDOW;
  32.     search.type = ID_SCROLL_BAR;
  33.  
  34.     // Match with the appropriate Windows 3.0 flags.
  35.     MSWindowsStyle |= WS_BORDER;
  36.     if (FlagSet(sbFlags, SBF_VERTICAL))
  37.         MSWindowsStyle |= SBS_VERT;
  38.     if (FlagSet(sbFlags, SBF_HORIZONTAL))
  39.         MSWindowsStyle |= SBS_HORZ;
  40. }
  41.  
  42. UIW_SCROLL_BAR::Event(const UI_EVENT &event)
  43. {
  44.     // Return if scroll bar is attached to text or window.
  45.     if (FlagSet(MSWindowsStyle, WS_VSCROLL) || FlagSet(MSWindowsStyle, WS_HSCROLL))
  46.         return (S_UNKNOWN);
  47.  
  48.     // Switch on the event type.
  49.     int ccode = UI_WINDOW_OBJECT::LogicalEvent(event, ID_SCROLL_BAR);
  50.     switch (ccode)
  51.     {
  52.     case S_CREATE:
  53.          // Compute the scroll bar position.
  54.         display->RegionConvert(relative, &woStatus, WOS_GRAPHICS);
  55.         UI_WINDOW_OBJECT::RegionMax(FlagSet(sbFlags, SBF_VERTICAL) ? TRUE : FALSE);
  56.         if (FlagSet(woFlags, WOF_NON_FIELD_REGION) && FlagSet(sbFlags, SBF_VERTICAL))
  57.             true.left = true.right - GetSystemMetrics(SM_CXVSCROLL);
  58.         else if (FlagSet(woFlags, WOF_NON_FIELD_REGION) && FlagSet(sbFlags, SBF_HORIZONTAL))
  59.             true.top = true.bottom - GetSystemMetrics(SM_CYHSCROLL);
  60.         else if (FlagSet(sbFlags, SBF_VERTICAL))
  61.             true.right = true.left + GetSystemMetrics(SM_CXVSCROLL);
  62.         else if (FlagSet(sbFlags, SBF_HORIZONTAL))
  63.             true.bottom = true.top + GetSystemMetrics(SM_CYHSCROLL);
  64.         true.bottom += 1;
  65.         true.right += 1;
  66.  
  67.         UI_WINDOW_OBJECT *root = parent;
  68.         while (root->parent && !root->hWnd)
  69.             root = root->parent;
  70.         if (!root->hWnd)
  71.             break;
  72.         POINT client = { 0, 0 };
  73.         ClientToScreen(root->hWnd, &client);
  74.  
  75.         if (!hWnd)
  76.         {
  77.             hWnd = CreateWindow("ScrollBar", NULL,
  78.                 WS_CHILD | WS_VISIBLE | MSWindowsStyle,
  79.                 true.left - client.x, true.top - client.y,
  80.                 true.right - true.left, true.bottom - true.top,
  81.                 root->hWnd, 1, ((UI_MSWINDOWS_DISPLAY *)display)->hInstance, NULL);
  82.             screenID = hWnd;
  83.         }
  84.         else
  85.         {
  86.             RECT windowRect;
  87.             GetWindowRect(hWnd, &windowRect);
  88.             if (true.left != windowRect.left || true.top != windowRect.top ||
  89.                 true.right != windowRect.right || true.bottom != windowRect.bottom)
  90.             {
  91.                 MoveWindow(hWnd, true.left - client.x, true.top - client.y,
  92.                     true.right - true.left, true.bottom - true.top, TRUE);
  93.                 SendMessage(hWnd, WM_NCPAINT, 0, 0x0L);
  94.             }
  95.         }
  96.  
  97.         if (FlagSet(woAdvancedStatus, WOAS_TOO_SMALL))
  98.         {
  99.             SendMessage(hWnd, WM_KILLFOCUS, parent->hWnd, 0L);
  100.             SendMessage(hWnd, WM_ENABLE, 0, 0);
  101.         }
  102.         else
  103.             SendMessage(hWnd, WM_ENABLE, 1, 0);
  104.         break;
  105.  
  106.     case S_SCROLL_VERTICAL:
  107.     case S_SCROLL_HORIZONTAL:
  108.     case S_SCROLL_VERTICAL_SET:
  109.     case S_SCROLL_HORIZONTAL_SET:
  110.         if ((ccode == S_SCROLL_VERTICAL_SET && FlagSet(sbFlags, SBF_VERTICAL)) ||
  111.             (ccode == S_SCROLL_HORIZONTAL_SET && FlagSet(sbFlags, SBF_HORIZONTAL)))
  112.         {
  113.             showing = event.scroll.showing;
  114.             maximum = event.scroll.maximum;
  115.             current = event.scroll.current;
  116.             if (current > maximum)
  117.                 current = maximum;
  118.             SetScrollRange(hWnd, SB_CTL, 0, maximum, 0);
  119.             if (GetScrollPos(hWnd, SB_CTL) != current)
  120.                 SetScrollPos(hWnd, SB_CTL, current, 1);
  121.         }
  122.         else if ((ccode == S_SCROLL_VERTICAL && FlagSet(sbFlags, SBF_VERTICAL)) ||
  123.             (ccode == S_SCROLL_HORIZONTAL && FlagSet(sbFlags, SBF_HORIZONTAL)))
  124.         {
  125.             current -= event.scroll.delta;
  126.             if (current < 0)
  127.                 current = 0;
  128.             else if (current > maximum)
  129.                 current = maximum;
  130.             if (GetScrollPos(hWnd, SB_CTL) != current)
  131.                 SetScrollPos(hWnd, SB_CTL, current, 1);
  132.         }
  133.         else if (previous)
  134.         {
  135.             Previous()->Event(event);
  136.             break;
  137.         }
  138.         break;
  139.  
  140.     case L_BEGIN_SELECT:
  141.         if (FlagSet(sbFlags, SBF_CORNER) || FlagSet(woAdvancedStatus, WOAS_TOO_SMALL))
  142.             break;
  143.         SendMessage(hWnd, WM_LBUTTONDOWN, 0, event.position.column -
  144.             true.left + ((DWORD)(event.position.line - true.top) << 16));
  145.         break;
  146.  
  147.     case L_CONTINUE_SELECT:
  148.         if (FlagSet(sbFlags, SBF_CORNER) || FlagSet(woAdvancedStatus, WOAS_TOO_SMALL))
  149.             break;
  150.         SendMessage(hWnd, WM_MOUSEMOVE, 0, event.position.column -
  151.             true.left + ((DWORD)(event.position.line - true.top) << 16));
  152.         break;
  153.  
  154.     case L_END_SELECT:
  155.         if (!event.rawCode || FlagSet(sbFlags, SBF_CORNER) || FlagSet(woAdvancedStatus, WOAS_TOO_SMALL))
  156.             break;
  157.  
  158.         UI_EVENT tEvent;
  159.         switch (event.rawCode)
  160.         {
  161.         case SB_BOTTOM:
  162.         case SB_PAGEDOWN:
  163.             tEvent.type = L_PGDN;
  164.             break;
  165.  
  166.         case SB_TOP:
  167.         case SB_PAGEUP:
  168.             tEvent.type = L_PGUP;
  169.             break;
  170.  
  171.         default:
  172.             tEvent.type = (FlagSet(sbFlags, SBF_HORIZONTAL)) ?
  173.                 S_SCROLL_HORIZONTAL : S_SCROLL_VERTICAL;
  174.             tEvent.scroll.delta = (event.rawCode == SB_LINEDOWN) ? -1 : 1;
  175.             break;
  176.  
  177.         }
  178.         if (Next())
  179.             Next()->Event(tEvent);
  180.         break;
  181.  
  182.     default:
  183.         ccode = S_UNKNOWN;
  184.         break;
  185.     }
  186.  
  187.     // Return the event control code.
  188.     return (ccode);
  189. }
  190.  
  191. void *UIW_SCROLL_BAR::Information(INFORMATION_REQUEST request, void *data)
  192. {
  193.     if (request == GET_NUMBERID_OBJECT || request == GET_STRINGID_OBJECT ||
  194.         request == PRINT_INFORMATION)
  195.         return (UIW_WINDOW::Information(request, data));
  196.     else
  197.         return (UI_WINDOW_OBJECT::Information(request, data));
  198. }
  199.  
  200. #pragma argsused
  201. void UIW_SCROLL_BAR::CornerCompute()
  202. {
  203. }
  204.  
  205. #pragma argsused
  206. void UIW_SCROLL_BAR::HorizontalCompute(int startButton, int endButton)
  207. {
  208. }
  209.  
  210. #pragma argsused
  211. void UIW_SCROLL_BAR::VerticalCompute(int startButton, int endButton)
  212. {
  213. }
  214.  
  215. #ifdef ZIL_LOAD
  216. UIW_SCROLL_BAR::UIW_SCROLL_BAR(const char *name, UI_STORAGE *file, USHORT loadFlags) :
  217.     UIW_WINDOW(name, file, loadFlags | L_SUB_LEVEL),
  218.     current(0), showing(0), maximum(0)
  219. {
  220.     windowID[0] = ID_SCROLL_BAR;
  221.     windowID[1] = ID_WINDOW;
  222.  
  223.     if (!file)
  224.         file = _storage;
  225.     file->Load(&sbFlags);
  226.     int i = 0;
  227.     for (UI_WINDOW_OBJECT *object = First(); object; object = object->Next())
  228.     {
  229.         if (i >= TOP_REGION)
  230.             object->WindowID(0, ID_SCROLL_BAR);
  231.         button[i++] = (UIW_BUTTON *)object;
  232.     }
  233.     if (!FlagSet(loadFlags, L_SUB_LEVEL) && FlagSet(file->stStatus, STS_TEMPORARY))
  234.         delete file;
  235. }
  236. #endif
  237.  
  238. #ifdef ZIL_STORE
  239. void UIW_SCROLL_BAR::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
  240. {
  241.     UIW_WINDOW::Store(name, file, storeFlags | S_SUB_LEVEL);
  242.     file->Store(sbFlags);
  243.     if (!FlagSet(storeFlags, S_SUB_LEVEL))
  244.         file->ObjectSize(name, search);
  245. }
  246. #endif
  247.