home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / BDSIDE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-11  |  7.9 KB  |  307 lines

  1. /*
  2.     bdside.c    12/18/88
  3.  
  4.     % an elevator side bar with scroll lights and scrolling mouse support.
  5.  
  6.     OWL 1.1
  7.     Copyright (c) 1988, 1989 by Oakland Group, Inc.
  8.     ALL RIGHTS RESERVED.
  9.  
  10.     Revision History:
  11.     -----------------
  12.      5/28/89 jmd    added Shadow (non) support
  13. */
  14.  
  15. #include "oakhead.h"
  16. #include "disppriv.h"
  17. #include "scancode.h"    /* for mouse pseudo-scancodes */
  18. #include "strdecl.h"
  19.  
  20. #include "bordobj.h"
  21. #include "bordod.h"
  22. #include "bdsideod.h"
  23.  
  24. #define    VSCROLL_BAR    "\262\262\262"
  25. #define VSIDE_BAR    "\260\260\260"
  26.  
  27. #ifdef BORDER_CHARS
  28. #    define    uplight(bdsided)    ((bdsided->up) ? "\x1e" : &bdsided->back)
  29. #    define    downlight(bdsided)    ((bdsided->down) ? "\x1f" : &bdsided->back)
  30.  
  31. #    define    leftlight(bdsided)    ((flag) ? "\x11" : " ")
  32. #    define    rightlight(bdsided) ((flag) ? "\x10" : " ")
  33.  
  34. #else
  35. #    define    uplight(bdsided)    ((bdsided->up) ? "*" : &bdsided->back)
  36. #    define    downlight(bdsided)    ((bdsided->down) ? "*" : &bdsided->back)
  37.  
  38. #    define    leftlight(bdsided)    ((flag) ? "*" : " ")
  39. #    define    rightlight(bdsided) ((flag) ? "*" : " ")
  40. #endif
  41.  
  42. OSTATIC void OWLPRIV sidebar_mouse(_arg2(bdsidebar_od *, mev_struct *));
  43. OSTATIC void OWLPRIV light_scroll(_arg4(bdsidebar_od *, opoint *, boolean *, mev_struct *));
  44. /* -------------------------------------------------------------------------- */
  45.  
  46. int bd_sidebar(objdata, msg, indata, outdata)
  47.     VOID *objdata;
  48.     int msg;
  49.     VOID *indata;                /* message input data */
  50.     VOID *outdata;                /* message output data */
  51. /*
  52.     Example:
  53.                                        <--- Scroll Lights
  54.                                      I
  55.                                      X    <--- Elevator
  56.                                      I
  57.                                        <--- Scroll Lights
  58.  
  59.     Clicking the mouse on the scroll lights or the sidebar
  60.         scrolls the border's contents.
  61. */
  62. {
  63.     bdsidebar_od *bdsideod;
  64.     ocbox        cbox;
  65.     ptd_struct *ptd;
  66.     win_type    win;
  67.     mev_struct *mev;
  68.     byte        attr;
  69.  
  70.     bdsideod = (bdsidebar_od *)objdata;
  71.  
  72.     switch(msg) {
  73.     case OBJM_GETDATASIZE:
  74.         ((ogds_struct *) outdata)->odsize = sizeof(bdsidebar_od);
  75.         ((ogds_struct *) outdata)->xdsize = sizeof(border_xd);
  76.         ((ogds_struct *) outdata)->id = ID_BDSIDEBAR;
  77.         break;
  78.  
  79.     case OBJM_OPEN:
  80.         if (!border_DoRaw(&bdsideod->bdd, msg, indata, outdata)) {
  81.             return(FALSE);
  82.         }
  83.          bdsideod->back = ' ';
  84.  
  85.         bord_SetSides(bdsideod->bdd.win, 0, 0, 0, 1);
  86.  
  87.         bdsideod->eltop   = 1;
  88.         bdsideod->elbot   = win_GetHeight(bdsideod->bdd.win) - 2;
  89.         bord_GetVtBar(bdsideod->bdd.win, &bdsideod->eltop, &bdsideod->elbot,
  90.                                             &bdsideod->up, &bdsideod->down);
  91.         break;
  92.  
  93.     case BDM_SCROLL:
  94.         /* Adjust the up and down lights and the scroll bar */
  95.         win = bdsideod->bdd.win;
  96.  
  97.         cbox.toprow   = 0;
  98.         cbox.botrow   = win_GetHeight(win) - 1;
  99.         cbox.leftcol  = win_GetWidth(win);
  100.         cbox.rightcol = cbox.leftcol;
  101.  
  102.         bdsideod->eltop   = cbox.toprow + 1;
  103.         bdsideod->elbot   = cbox.botrow - 1;
  104.         bord_GetVtBar(win, &bdsideod->eltop, &bdsideod->elbot,
  105.                             &bdsideod->up, &bdsideod->down);
  106.  
  107.         win_PaintBox(win, &cbox);
  108.         break;
  109.  
  110.     case BDM_RESIZE:
  111.         /* our window has changed size, reset the scroll lights */
  112.         bdsideod->eltop   = 1;
  113.         bdsideod->elbot   = win_GetHeight(bdsideod->bdd.win) - 2;
  114.         bord_GetVtBar(bdsideod->bdd.win, &bdsideod->eltop, &bdsideod->elbot,
  115.                                             &bdsideod->up, &bdsideod->down);
  116.         break;
  117.  
  118.     case BDM_SHADOW:
  119.     case BDM_DRAW:
  120.         ptd = (ptd_struct *)indata;
  121.         win = bdsideod->bdd.win;
  122.         attr = (msg == BDM_DRAW) ? 
  123.             bord_GetAttr(bdsideod->bdd.win) : win_GetShadowAttr(bdsideod->bdd.win);
  124.  
  125.         /* Draw the scroll bar */
  126.  
  127.         cbox.leftcol  = win_GetWidth(win);
  128.         cbox.rightcol = cbox.leftcol;
  129.         cbox.toprow   = 1;
  130.         cbox.botrow   = win_GetHeight(win) - 2;
  131.         if (cbox.botrow >= cbox.toprow) {
  132.             ptd_DrawCharLine(ptd, VSIDE_BAR, &cbox, attr);
  133.  
  134.             cbox.toprow   = bdsideod->eltop;
  135.             cbox.botrow   = bdsideod->elbot;
  136.             ptd_DrawCharLine(ptd, VSCROLL_BAR, &cbox, attr);
  137.         }
  138.         /* Draw the scroll lights */
  139.         cbox.toprow = 0;
  140.         cbox.botrow = win_GetHeight(win) - 1;
  141.         if (cbox.botrow > cbox.toprow) {
  142.             /* Uplight */
  143.             ptd_DrawString(ptd, cbox.toprow, cbox.rightcol,
  144.                             uplight(bdsideod), attr, 1);
  145.             /* Downlight */
  146.             ptd_DrawString(ptd, cbox.botrow, cbox.rightcol,
  147.                             downlight(bdsideod), attr, 1);
  148.         }
  149.         /* Note: this border does not support a shadow
  150.                  so it doesn't pass up its DRAW msg 
  151.         */
  152.         break;
  153.  
  154.     case BDM_STARTMOUSE:
  155.     case BDM_ENDMOUSE:        /* Mouse left the border. */
  156.         return(border_DoRaw(&bdsideod->bdd, msg, indata, outdata));
  157.  
  158.     case BDM_MOUSE:
  159.         /* If mouse clicked on up or down light, then scroll. */
  160.         /* If mouse clicked on elevator, scroll in that fashion */
  161.  
  162.         mev = (mev_struct *) indata;
  163.         win = bdsideod->bdd.win;
  164.  
  165.         if (mev_GetCol(mev) == win_GetWidth(win) &&
  166.             mev_GetRow(mev) >= 0 &&
  167.             mev_GetRow(mev) <= win_GetHeight(win) - 1) {
  168.  
  169.             sidebar_mouse(bdsideod, mev);
  170.  
  171.             /* Don't offer to make this border's window the current window */
  172.             mev_ClearEvent(mev);
  173.         }
  174.         else {
  175.             /* pass message up to super class */
  176.             return(border_DoRaw(&bdsideod->bdd, msg, indata, outdata));
  177.         }
  178.         break;
  179.  
  180.     case OBJM_CLOSE:
  181.         /* No break; fall through to default */
  182.  
  183.     default:
  184.         return(border_DoRaw(&bdsideod->bdd, msg, indata, outdata));
  185.     }
  186.     return(1);
  187. }
  188. /* -------------------------------------------------------------------------- */
  189.  
  190. static void OWLPRIV sidebar_mouse(bdsideod, mev)
  191.     bdsidebar_od *bdsideod;
  192.     mev_struct *mev;
  193. /*
  194.     Mouse processing for bd_sidebar.
  195. */
  196. {
  197.     win_type    win;
  198.     opoint         mvpnt;
  199.     boolean    *actdirp;
  200.     int            elevh, barh;
  201.     int         prevrow;
  202.  
  203.     if (mev_IsButtonDown(mev)) {
  204.         if (bdsideod->bdd.debounced) {
  205.             return;
  206.         }
  207.     }
  208.     else {
  209.         bdsideod->bdd.debounced = FALSE;
  210.         return;
  211.     }
  212.     win = bdsideod->bdd.win;
  213.  
  214.     if (mev_GetRow(mev) == 0) {
  215.         /* Up arrow */
  216.         if (bdsideod->up) {
  217.             actdirp = &bdsideod->up;
  218.             mvpnt.x = 0;
  219.             mvpnt.y = -win_GetFontHeight(win);
  220.  
  221.             light_scroll(bdsideod, &mvpnt, actdirp, mev);
  222.         }
  223.     }
  224.     else if (mev_GetRow(mev) == win_GetHeight(win) - 1) {
  225.         /* Down arrow */
  226.         if (bdsideod->down) {
  227.             actdirp = &bdsideod->down;
  228.             mvpnt.x = 0;
  229.             mvpnt.y = win_GetFontHeight(win);
  230.  
  231.             light_scroll(bdsideod, &mvpnt, actdirp, mev);
  232.         }
  233.     }
  234.     else if (mev_GetRow(mev) > 0 &&
  235.              mev_GetRow(mev) < win_GetHeight(win) - 1 ) {
  236.  
  237.         /* Sidebar */
  238.         if ((barh = win_GetHeight(win) - 2) >= 2) {
  239.  
  240.             prevrow = mev_GetRow(mev);
  241.             mvpnt.x = 0;
  242.             elevh = bdsideod->elbot - bdsideod->eltop + 1;
  243.             for (;;) {
  244.                 mvpnt.y = ((mev_GetRow(mev) - prevrow) *
  245.                             barh * win_GetFontHeight(win)) / elevh;
  246.  
  247.                 if (mvpnt.y != 0) {
  248.                     /* Scroll window contents */
  249.                     /* Note that the SCROLLREQ is expected to call BDM_SCROLL */
  250.                     /* to reset the lights flags which we test to see if */
  251.                     /* scrolling is all done */
  252.  
  253.                     if ((mvpnt.y > 0 && bdsideod->down) ||
  254.                         (mvpnt.y < 0 && bdsideod->up)) {
  255.                         win_Do(win, WINM_SCROLLREQ, &mvpnt, NULL);
  256.  
  257.                         prevrow = mev_GetRow(mev);
  258.                     }
  259.                 }
  260.                 if (win_ReadEvent(win, mev) == MOU_EVENT) {
  261.                     if (!mev_IsButtonDown(mev)) {
  262.                         break;
  263.                     }
  264.                 /* else: ignore keystrokes */
  265.                 }
  266.             }
  267.         }
  268.     }
  269.     bdsideod->bdd.debounced = mev_IsButtonDown(mev);
  270. }
  271. /* -------------------------------------------------------------------------- */
  272.  
  273. static void OWLPRIV light_scroll(bdsideod, mvpnt, actdirp, mev)
  274.     bdsidebar_od *bdsideod;
  275.     opoint         *mvpnt;
  276.     boolean    *actdirp;
  277.     mev_struct *mev;
  278. {
  279.     win_type    win;
  280.     unsigned    holdtime;
  281.  
  282.     win = bdsideod->bdd.win;
  283.  
  284.     holdtime = 30;    /* Initial delay value = 1/3 second */
  285.  
  286.     for (;;) {
  287.         /* Scroll window contents */
  288.         /* Note that the SCROLLREQ is expected to call BDM_SCROLL */
  289.         /* to reset the lights flags which we test to see if */
  290.         /* scrolling is all done */
  291.         win_Do(win, WINM_SCROLLREQ, mvpnt, NULL);
  292.  
  293.         /* Break if dir is all used up now */
  294.         if (!(*actdirp)) {
  295.             bdsideod->bdd.debounced = TRUE;
  296.             break;
  297.         }
  298.         /* Break if mouse is no longer held down. Ignore keyhits */
  299.         if (win_MouseHoldDownTime(win, mev, holdtime) == MOU_EVENT) {
  300.             break;
  301.         }
  302.         holdtime = 5;
  303.     }
  304. }
  305. /* -------------------------------------------------------------------------- */
  306.  
  307.