home *** CD-ROM | disk | FTP | other *** search
- // Zinc Interface Library - SCROLL.CPP
- // COPYRIGHT (C) 1990, 1991. All Rights Reserved.
- // Zinc Software Incorporated. Pleasant Grove, Utah USA
-
- #include "ui_win.hpp"
-
- // Special button identifications - order is important.
- const int TOTAL_BUTTONS = 5;
- const int TOP_BUTTON = 0;
- const int LEFT_BUTTON = 0;
- const int BOTTOM_BUTTON = 1;
- const int RIGHT_BUTTON = 1;
- const int MIDDLE_BUTTON = 2;
- const int TOP_REGION = 3;
- const int LEFT_REGION = 3;
- const int BOTTOM_REGION = 4;
- const int RIGHT_REGION = 4;
-
- #pragma argsused
- void UIW_SCROLL_BAR::UserFunction(void *data, UI_EVENT &event)
- {
- }
-
- UIW_SCROLL_BAR::UIW_SCROLL_BAR(int left, int top, int width, int height,
- USHORT _sbFlags, USHORT _woFlags) :
- UIW_WINDOW(left, top, width, height, _woFlags, WOAF_NON_CURRENT),
- sbFlags(_sbFlags), current(0), showing(0), maximum(0)
- {
- // Initialize the slide information.
- windowID[0] = ID_SCROLL_BAR;
- windowID[1] = ID_WINDOW;
- search.type = ID_SCROLL_BAR;
-
- // Match with the appropriate Windows 3.0 flags.
- MSWindowsStyle |= WS_BORDER;
- if (FlagSet(sbFlags, SBF_VERTICAL))
- MSWindowsStyle |= SBS_VERT;
- if (FlagSet(sbFlags, SBF_HORIZONTAL))
- MSWindowsStyle |= SBS_HORZ;
- }
-
- UIW_SCROLL_BAR::Event(const UI_EVENT &event)
- {
- // Return if scroll bar is attached to text or window.
- if (FlagSet(MSWindowsStyle, WS_VSCROLL) || FlagSet(MSWindowsStyle, WS_HSCROLL))
- return (S_UNKNOWN);
-
- // Switch on the event type.
- int ccode = UI_WINDOW_OBJECT::LogicalEvent(event, ID_SCROLL_BAR);
- switch (ccode)
- {
- case S_CREATE:
- // Compute the scroll bar position.
- display->RegionConvert(relative, &woStatus, WOS_GRAPHICS);
- UI_WINDOW_OBJECT::RegionMax(FlagSet(sbFlags, SBF_VERTICAL) ? TRUE : FALSE);
- if (FlagSet(woFlags, WOF_NON_FIELD_REGION) && FlagSet(sbFlags, SBF_VERTICAL))
- true.left = true.right - GetSystemMetrics(SM_CXVSCROLL);
- else if (FlagSet(woFlags, WOF_NON_FIELD_REGION) && FlagSet(sbFlags, SBF_HORIZONTAL))
- true.top = true.bottom - GetSystemMetrics(SM_CYHSCROLL);
- else if (FlagSet(sbFlags, SBF_VERTICAL))
- true.right = true.left + GetSystemMetrics(SM_CXVSCROLL);
- else if (FlagSet(sbFlags, SBF_HORIZONTAL))
- true.bottom = true.top + GetSystemMetrics(SM_CYHSCROLL);
- true.bottom += 1;
- true.right += 1;
-
- UI_WINDOW_OBJECT *root = parent;
- while (root->parent && !root->hWnd)
- root = root->parent;
- if (!root->hWnd)
- break;
- POINT client = { 0, 0 };
- ClientToScreen(root->hWnd, &client);
-
- if (!hWnd)
- {
- hWnd = CreateWindow("ScrollBar", NULL,
- WS_CHILD | WS_VISIBLE | MSWindowsStyle,
- true.left - client.x, true.top - client.y,
- true.right - true.left, true.bottom - true.top,
- root->hWnd, 1, ((UI_MSWINDOWS_DISPLAY *)display)->hInstance, NULL);
- screenID = hWnd;
- }
- else
- {
- RECT windowRect;
- GetWindowRect(hWnd, &windowRect);
- if (true.left != windowRect.left || true.top != windowRect.top ||
- true.right != windowRect.right || true.bottom != windowRect.bottom)
- {
- MoveWindow(hWnd, true.left - client.x, true.top - client.y,
- true.right - true.left, true.bottom - true.top, TRUE);
- SendMessage(hWnd, WM_NCPAINT, 0, 0x0L);
- }
- }
-
- if (FlagSet(woAdvancedStatus, WOAS_TOO_SMALL))
- {
- SendMessage(hWnd, WM_KILLFOCUS, parent->hWnd, 0L);
- SendMessage(hWnd, WM_ENABLE, 0, 0);
- }
- else
- SendMessage(hWnd, WM_ENABLE, 1, 0);
- break;
-
- case S_SCROLL_VERTICAL:
- case S_SCROLL_HORIZONTAL:
- case S_SCROLL_VERTICAL_SET:
- case S_SCROLL_HORIZONTAL_SET:
- if ((ccode == S_SCROLL_VERTICAL_SET && FlagSet(sbFlags, SBF_VERTICAL)) ||
- (ccode == S_SCROLL_HORIZONTAL_SET && FlagSet(sbFlags, SBF_HORIZONTAL)))
- {
- showing = event.scroll.showing;
- maximum = event.scroll.maximum;
- current = event.scroll.current;
- if (current > maximum)
- current = maximum;
- SetScrollRange(hWnd, SB_CTL, 0, maximum, 0);
- if (GetScrollPos(hWnd, SB_CTL) != current)
- SetScrollPos(hWnd, SB_CTL, current, 1);
- }
- else if ((ccode == S_SCROLL_VERTICAL && FlagSet(sbFlags, SBF_VERTICAL)) ||
- (ccode == S_SCROLL_HORIZONTAL && FlagSet(sbFlags, SBF_HORIZONTAL)))
- {
- current -= event.scroll.delta;
- if (current < 0)
- current = 0;
- else if (current > maximum)
- current = maximum;
- if (GetScrollPos(hWnd, SB_CTL) != current)
- SetScrollPos(hWnd, SB_CTL, current, 1);
- }
- else if (previous)
- {
- Previous()->Event(event);
- break;
- }
- break;
-
- case L_BEGIN_SELECT:
- if (FlagSet(sbFlags, SBF_CORNER) || FlagSet(woAdvancedStatus, WOAS_TOO_SMALL))
- break;
- SendMessage(hWnd, WM_LBUTTONDOWN, 0, event.position.column -
- true.left + ((DWORD)(event.position.line - true.top) << 16));
- break;
-
- case L_CONTINUE_SELECT:
- if (FlagSet(sbFlags, SBF_CORNER) || FlagSet(woAdvancedStatus, WOAS_TOO_SMALL))
- break;
- SendMessage(hWnd, WM_MOUSEMOVE, 0, event.position.column -
- true.left + ((DWORD)(event.position.line - true.top) << 16));
- break;
-
- case L_END_SELECT:
- if (!event.rawCode || FlagSet(sbFlags, SBF_CORNER) || FlagSet(woAdvancedStatus, WOAS_TOO_SMALL))
- break;
-
- UI_EVENT tEvent;
- switch (event.rawCode)
- {
- case SB_BOTTOM:
- case SB_PAGEDOWN:
- tEvent.type = L_PGDN;
- break;
-
- case SB_TOP:
- case SB_PAGEUP:
- tEvent.type = L_PGUP;
- break;
-
- default:
- tEvent.type = (FlagSet(sbFlags, SBF_HORIZONTAL)) ?
- S_SCROLL_HORIZONTAL : S_SCROLL_VERTICAL;
- tEvent.scroll.delta = (event.rawCode == SB_LINEDOWN) ? -1 : 1;
- break;
-
- }
- if (Next())
- Next()->Event(tEvent);
- break;
-
- default:
- ccode = S_UNKNOWN;
- break;
- }
-
- // Return the event control code.
- return (ccode);
- }
-
- void *UIW_SCROLL_BAR::Information(INFORMATION_REQUEST request, void *data)
- {
- if (request == GET_NUMBERID_OBJECT || request == GET_STRINGID_OBJECT ||
- request == PRINT_INFORMATION)
- return (UIW_WINDOW::Information(request, data));
- else
- return (UI_WINDOW_OBJECT::Information(request, data));
- }
-
- #pragma argsused
- void UIW_SCROLL_BAR::CornerCompute()
- {
- }
-
- #pragma argsused
- void UIW_SCROLL_BAR::HorizontalCompute(int startButton, int endButton)
- {
- }
-
- #pragma argsused
- void UIW_SCROLL_BAR::VerticalCompute(int startButton, int endButton)
- {
- }
-
- #ifdef ZIL_LOAD
- UIW_SCROLL_BAR::UIW_SCROLL_BAR(const char *name, UI_STORAGE *file, USHORT loadFlags) :
- UIW_WINDOW(name, file, loadFlags | L_SUB_LEVEL),
- current(0), showing(0), maximum(0)
- {
- windowID[0] = ID_SCROLL_BAR;
- windowID[1] = ID_WINDOW;
-
- if (!file)
- file = _storage;
- file->Load(&sbFlags);
- int i = 0;
- for (UI_WINDOW_OBJECT *object = First(); object; object = object->Next())
- {
- if (i >= TOP_REGION)
- object->WindowID(0, ID_SCROLL_BAR);
- button[i++] = (UIW_BUTTON *)object;
- }
- if (!FlagSet(loadFlags, L_SUB_LEVEL) && FlagSet(file->stStatus, STS_TEMPORARY))
- delete file;
- }
- #endif
-
- #ifdef ZIL_STORE
- void UIW_SCROLL_BAR::Store(const char *name, UI_STORAGE *file, USHORT storeFlags)
- {
- UIW_WINDOW::Store(name, file, storeFlags | S_SUB_LEVEL);
- file->Store(sbFlags);
- if (!FlagSet(storeFlags, S_SUB_LEVEL))
- file->ObjectSize(name, search);
- }
- #endif
-