home *** CD-ROM | disk | FTP | other *** search
- /*
- bdside.c 12/18/88
-
- % an elevator side bar with scroll lights and scrolling mouse support.
-
- OWL 1.1
- Copyright (c) 1988, 1989 by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 5/28/89 jmd added Shadow (non) support
- */
-
- #include "oakhead.h"
- #include "disppriv.h"
- #include "scancode.h" /* for mouse pseudo-scancodes */
- #include "strdecl.h"
-
- #include "bordobj.h"
- #include "bordod.h"
- #include "bdsideod.h"
-
- #define VSCROLL_BAR "\262\262\262"
- #define VSIDE_BAR "\260\260\260"
-
- #ifdef BORDER_CHARS
- # define uplight(bdsided) ((bdsided->up) ? "\x1e" : &bdsided->back)
- # define downlight(bdsided) ((bdsided->down) ? "\x1f" : &bdsided->back)
-
- # define leftlight(bdsided) ((flag) ? "\x11" : " ")
- # define rightlight(bdsided) ((flag) ? "\x10" : " ")
-
- #else
- # define uplight(bdsided) ((bdsided->up) ? "*" : &bdsided->back)
- # define downlight(bdsided) ((bdsided->down) ? "*" : &bdsided->back)
-
- # define leftlight(bdsided) ((flag) ? "*" : " ")
- # define rightlight(bdsided) ((flag) ? "*" : " ")
- #endif
-
- OSTATIC void OWLPRIV sidebar_mouse(_arg2(bdsidebar_od *, mev_struct *));
- OSTATIC void OWLPRIV light_scroll(_arg4(bdsidebar_od *, opoint *, boolean *, mev_struct *));
- /* -------------------------------------------------------------------------- */
-
- int bd_sidebar(objdata, msg, indata, outdata)
- VOID *objdata;
- int msg;
- VOID *indata; /* message input data */
- VOID *outdata; /* message output data */
- /*
- Example:
- <--- Scroll Lights
- I
- X <--- Elevator
- I
- <--- Scroll Lights
-
- Clicking the mouse on the scroll lights or the sidebar
- scrolls the border's contents.
- */
- {
- bdsidebar_od *bdsideod;
- ocbox cbox;
- ptd_struct *ptd;
- win_type win;
- mev_struct *mev;
- byte attr;
-
- bdsideod = (bdsidebar_od *)objdata;
-
- switch(msg) {
- case OBJM_GETDATASIZE:
- ((ogds_struct *) outdata)->odsize = sizeof(bdsidebar_od);
- ((ogds_struct *) outdata)->xdsize = sizeof(border_xd);
- ((ogds_struct *) outdata)->id = ID_BDSIDEBAR;
- break;
-
- case OBJM_OPEN:
- if (!border_DoRaw(&bdsideod->bdd, msg, indata, outdata)) {
- return(FALSE);
- }
- bdsideod->back = ' ';
-
- bord_SetSides(bdsideod->bdd.win, 0, 0, 0, 1);
-
- bdsideod->eltop = 1;
- bdsideod->elbot = win_GetHeight(bdsideod->bdd.win) - 2;
- bord_GetVtBar(bdsideod->bdd.win, &bdsideod->eltop, &bdsideod->elbot,
- &bdsideod->up, &bdsideod->down);
- break;
-
- case BDM_SCROLL:
- /* Adjust the up and down lights and the scroll bar */
- win = bdsideod->bdd.win;
-
- cbox.toprow = 0;
- cbox.botrow = win_GetHeight(win) - 1;
- cbox.leftcol = win_GetWidth(win);
- cbox.rightcol = cbox.leftcol;
-
- bdsideod->eltop = cbox.toprow + 1;
- bdsideod->elbot = cbox.botrow - 1;
- bord_GetVtBar(win, &bdsideod->eltop, &bdsideod->elbot,
- &bdsideod->up, &bdsideod->down);
-
- win_PaintBox(win, &cbox);
- break;
-
- case BDM_RESIZE:
- /* our window has changed size, reset the scroll lights */
- bdsideod->eltop = 1;
- bdsideod->elbot = win_GetHeight(bdsideod->bdd.win) - 2;
- bord_GetVtBar(bdsideod->bdd.win, &bdsideod->eltop, &bdsideod->elbot,
- &bdsideod->up, &bdsideod->down);
- break;
-
- case BDM_SHADOW:
- case BDM_DRAW:
- ptd = (ptd_struct *)indata;
- win = bdsideod->bdd.win;
- attr = (msg == BDM_DRAW) ?
- bord_GetAttr(bdsideod->bdd.win) : win_GetShadowAttr(bdsideod->bdd.win);
-
- /* Draw the scroll bar */
-
- cbox.leftcol = win_GetWidth(win);
- cbox.rightcol = cbox.leftcol;
- cbox.toprow = 1;
- cbox.botrow = win_GetHeight(win) - 2;
- if (cbox.botrow >= cbox.toprow) {
- ptd_DrawCharLine(ptd, VSIDE_BAR, &cbox, attr);
-
- cbox.toprow = bdsideod->eltop;
- cbox.botrow = bdsideod->elbot;
- ptd_DrawCharLine(ptd, VSCROLL_BAR, &cbox, attr);
- }
- /* Draw the scroll lights */
- cbox.toprow = 0;
- cbox.botrow = win_GetHeight(win) - 1;
- if (cbox.botrow > cbox.toprow) {
- /* Uplight */
- ptd_DrawString(ptd, cbox.toprow, cbox.rightcol,
- uplight(bdsideod), attr, 1);
- /* Downlight */
- ptd_DrawString(ptd, cbox.botrow, cbox.rightcol,
- downlight(bdsideod), attr, 1);
- }
- /* Note: this border does not support a shadow
- so it doesn't pass up its DRAW msg
- */
- break;
-
- case BDM_STARTMOUSE:
- case BDM_ENDMOUSE: /* Mouse left the border. */
- return(border_DoRaw(&bdsideod->bdd, msg, indata, outdata));
-
- case BDM_MOUSE:
- /* If mouse clicked on up or down light, then scroll. */
- /* If mouse clicked on elevator, scroll in that fashion */
-
- mev = (mev_struct *) indata;
- win = bdsideod->bdd.win;
-
- if (mev_GetCol(mev) == win_GetWidth(win) &&
- mev_GetRow(mev) >= 0 &&
- mev_GetRow(mev) <= win_GetHeight(win) - 1) {
-
- sidebar_mouse(bdsideod, mev);
-
- /* Don't offer to make this border's window the current window */
- mev_ClearEvent(mev);
- }
- else {
- /* pass message up to super class */
- return(border_DoRaw(&bdsideod->bdd, msg, indata, outdata));
- }
- break;
-
- case OBJM_CLOSE:
- /* No break; fall through to default */
-
- default:
- return(border_DoRaw(&bdsideod->bdd, msg, indata, outdata));
- }
- return(1);
- }
- /* -------------------------------------------------------------------------- */
-
- static void OWLPRIV sidebar_mouse(bdsideod, mev)
- bdsidebar_od *bdsideod;
- mev_struct *mev;
- /*
- Mouse processing for bd_sidebar.
- */
- {
- win_type win;
- opoint mvpnt;
- boolean *actdirp;
- int elevh, barh;
- int prevrow;
-
- if (mev_IsButtonDown(mev)) {
- if (bdsideod->bdd.debounced) {
- return;
- }
- }
- else {
- bdsideod->bdd.debounced = FALSE;
- return;
- }
- win = bdsideod->bdd.win;
-
- if (mev_GetRow(mev) == 0) {
- /* Up arrow */
- if (bdsideod->up) {
- actdirp = &bdsideod->up;
- mvpnt.x = 0;
- mvpnt.y = -win_GetFontHeight(win);
-
- light_scroll(bdsideod, &mvpnt, actdirp, mev);
- }
- }
- else if (mev_GetRow(mev) == win_GetHeight(win) - 1) {
- /* Down arrow */
- if (bdsideod->down) {
- actdirp = &bdsideod->down;
- mvpnt.x = 0;
- mvpnt.y = win_GetFontHeight(win);
-
- light_scroll(bdsideod, &mvpnt, actdirp, mev);
- }
- }
- else if (mev_GetRow(mev) > 0 &&
- mev_GetRow(mev) < win_GetHeight(win) - 1 ) {
-
- /* Sidebar */
- if ((barh = win_GetHeight(win) - 2) >= 2) {
-
- prevrow = mev_GetRow(mev);
- mvpnt.x = 0;
- elevh = bdsideod->elbot - bdsideod->eltop + 1;
- for (;;) {
- mvpnt.y = ((mev_GetRow(mev) - prevrow) *
- barh * win_GetFontHeight(win)) / elevh;
-
- if (mvpnt.y != 0) {
- /* Scroll window contents */
- /* Note that the SCROLLREQ is expected to call BDM_SCROLL */
- /* to reset the lights flags which we test to see if */
- /* scrolling is all done */
-
- if ((mvpnt.y > 0 && bdsideod->down) ||
- (mvpnt.y < 0 && bdsideod->up)) {
- win_Do(win, WINM_SCROLLREQ, &mvpnt, NULL);
-
- prevrow = mev_GetRow(mev);
- }
- }
- if (win_ReadEvent(win, mev) == MOU_EVENT) {
- if (!mev_IsButtonDown(mev)) {
- break;
- }
- /* else: ignore keystrokes */
- }
- }
- }
- }
- bdsideod->bdd.debounced = mev_IsButtonDown(mev);
- }
- /* -------------------------------------------------------------------------- */
-
- static void OWLPRIV light_scroll(bdsideod, mvpnt, actdirp, mev)
- bdsidebar_od *bdsideod;
- opoint *mvpnt;
- boolean *actdirp;
- mev_struct *mev;
- {
- win_type win;
- unsigned holdtime;
-
- win = bdsideod->bdd.win;
-
- holdtime = 30; /* Initial delay value = 1/3 second */
-
- for (;;) {
- /* Scroll window contents */
- /* Note that the SCROLLREQ is expected to call BDM_SCROLL */
- /* to reset the lights flags which we test to see if */
- /* scrolling is all done */
- win_Do(win, WINM_SCROLLREQ, mvpnt, NULL);
-
- /* Break if dir is all used up now */
- if (!(*actdirp)) {
- bdsideod->bdd.debounced = TRUE;
- break;
- }
- /* Break if mouse is no longer held down. Ignore keyhits */
- if (win_MouseHoldDownTime(win, mev, holdtime) == MOU_EVENT) {
- break;
- }
- holdtime = 5;
- }
- }
- /* -------------------------------------------------------------------------- */
-
-