home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / BDBOXLT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-12  |  4.5 KB  |  162 lines

  1. /*
  2.     bdboxlt.c    7/27/88
  3.  
  4.     % box border with scroll lights.
  5.  
  6.     OWL 1.2
  7.     Copyright (c) 1988, by Oakland Group, Inc.
  8.     ALL RIGHTS RESERVED.
  9.  
  10.     Revision History:
  11.     -----------------
  12.      9/12/88 jmd    Added in and out data
  13.     11/13/88 jmd    Upgraded to new border stuff
  14.     11/20/88 jmd    Added ID to obj struct
  15.     12/20/88 jmd    removed SETSIZE msg
  16.  
  17.      5/28/89 jmd    added Shadow support
  18.  
  19.     11/06/89 jmd    removed DoRaw macros
  20.      2/21/90 ted    Added SetCharSize(TRUE) because border won't work otherwise.
  21.      3/28/90 jmd    ansi-fied
  22. */
  23.  
  24. #include "oakhead.h"
  25. #include "disppriv.h"
  26. #include "bordobj.h"
  27. #include "bordod.h"
  28.  
  29. #define OUTER_BOX     "\332\304\277\263\331\304\300\263"
  30.  
  31. /* scroll light macros */
  32. #ifdef BORDER_CHARS
  33. #    define    uplight(flag)    ((flag) ? "\030" : "\263")
  34. #    define    downlight(flag)    ((flag) ? "\031" : "\263")
  35. #else
  36. #    define    uplight(flag)    ((flag) ? "*" : "\263")
  37. #    define    downlight(flag)    ((flag) ? "*" : "\263")
  38. #endif
  39.  
  40. /* border object data */
  41.  
  42. typedef struct _bdboxlightod {
  43.     border_od    bdd;              /* common object super class */
  44.     boolean      up;                /* up and down lights */
  45.     boolean        down;
  46. } bdboxlight_od;
  47.  
  48. int bd_boxlight(VOID *objdata, int msg, VOID *indata, VOID *outdata)
  49. /*
  50.     This is a simple single lined border.
  51.     With an overwritten title and scroll lights on the bottom.
  52.     The title is pointed to by the border data pointer.
  53.     Example:
  54.                      +-----Title-----+
  55.                      |               *  <--- Scroll Lights
  56.                      |               |
  57.                      |               |
  58.                      |               *  <--- Scroll Lights
  59.                      +---------------+
  60. */
  61. {
  62.     bdboxlight_od     *bdboxltd;
  63.     ocbox        cbox;
  64.     ptd_struct *ptd;
  65.     int            tw, len;
  66.     boolean        oldup, olddown;
  67.     boolean        left, right;        /* dummy values */
  68.     byte        attr;
  69.  
  70.     bdboxltd = (bdboxlight_od *)objdata;
  71.  
  72.     switch(msg) {
  73.     case OBJM_GETDATASIZE:
  74.         ((ogds_struct *) outdata)->odsize = sizeof(bdboxlight_od);
  75.         ((ogds_struct *) outdata)->xdsize = sizeof(border_xd);
  76.         ((ogds_struct *) outdata)->id = ID_BDBOXLIGHT;
  77.         break;
  78.  
  79.     case OBJM_OPEN:
  80.         if (!border_Class(&bdboxltd->bdd, msg, indata, outdata)) {
  81.             return(FALSE);
  82.         }
  83.         win_SetCharSize(bdboxltd->bdd.win, TRUE);    /* This bord must be charsize */
  84.         bord_SetSides(bdboxltd->bdd.win, -1, -1, 1, 1);
  85.  
  86.         bord_GetLights(bdboxltd->bdd.win, &bdboxltd->up, &bdboxltd->down, &left, &right);
  87.         break;
  88.  
  89.     case BDM_SETTITLE:
  90.         if (bdboxltd->bdd.title != NULL) {
  91.             ofree(OA_BDTITLE, (VOID *) bdboxltd->bdd.title);
  92.             bdboxltd->bdd.title = NULL;
  93.         }
  94.  
  95.         if (indata != NULL && (bdboxltd->bdd.title = (char *) omalloc(OA_BDTITLE, strlen((char *)indata) + 1)) != NULL) {
  96.             strcpy(bdboxltd->bdd.title, (char *) indata);
  97.         }
  98.         break;
  99.  
  100.     case BDM_RESIZE:
  101.         /* our window has changed size, reset the scroll lights */
  102.         bord_GetLights(bdboxltd->bdd.win, &bdboxltd->up, &bdboxltd->down, &left, &right);
  103.         break;
  104.  
  105.     case BDM_SCROLL:
  106.         /* adjust the up and down lights */
  107.         oldup = bdboxltd->up;
  108.         olddown = bdboxltd->down;
  109.         bord_GetLights(bdboxltd->bdd.win, &bdboxltd->up, &bdboxltd->down, &left, &right);
  110.  
  111.         /* Only paint if arrows have changed */
  112.         if (oldup != bdboxltd->up || olddown != bdboxltd->down) {
  113.             /* paint up arrow */
  114.             cbox.toprow   = 0;
  115.             cbox.leftcol  = win_GetWidth(bdboxltd->bdd.win);
  116.             cbox.botrow   = cbox.toprow;
  117.             cbox.rightcol = cbox.leftcol;
  118.             win_PaintBox(bdboxltd->bdd.win, &cbox);
  119.             
  120.             /* paint down arrow */
  121.             cbox.toprow   = win_GetHeight(bdboxltd->bdd.win) - 1;
  122.             cbox.botrow   = cbox.toprow;
  123.             win_PaintBox(bdboxltd->bdd.win, &cbox);
  124.         }
  125.         break;
  126.  
  127.     case BDM_SHADOW:
  128.     case BDM_DRAW:
  129.         /* draw the border */
  130.         ptd = (ptd_struct *)indata;
  131.  
  132.         /* draw the box */
  133.         attr = (msg == BDM_DRAW) ? 
  134.             bord_GetAttr(bdboxltd->bdd.win) : win_GetShadowAttr(bdboxltd->bdd.win);
  135.  
  136.         bord_GetBox(bdboxltd->bdd.win, &cbox);
  137.         ptd_DrawCharBox(ptd, OUTER_BOX, &cbox, attr);
  138.  
  139.         /* draw the title if there is one */
  140.         if (bdboxltd->bdd.title != NULL) {
  141.             tw = win_GetWidth(bdboxltd->bdd.win);
  142.             len = strlen(bdboxltd->bdd.title);
  143.             len = (len > tw) ? tw : len;
  144.             ptd_DrawString(ptd, -1, (tw - len) / 2, bdboxltd->bdd.title, attr, len);
  145.         }
  146.  
  147.         /* draw the scroll lights */
  148.         /* uplight */
  149.         ptd_DrawString(ptd, 0, win_GetWidth(bdboxltd->bdd.win), uplight(bdboxltd->up), attr, 1);
  150.  
  151.         /* downlight */
  152.         ptd_DrawString(ptd, win_GetHeight(bdboxltd->bdd.win) - 1, win_GetWidth(bdboxltd->bdd.win), downlight(bdboxltd->down), attr, 1);
  153.  
  154.         /* else no break; pass message up to superclass */
  155.  
  156.     default:
  157.         return(border_Class(&bdboxltd->bdd, msg, indata, outdata));
  158.     }
  159.     return(1);
  160. }
  161.  
  162.