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

  1. /*
  2.     bdtitle.c    2/16/87
  3.  
  4.     % border with a title and scroll lights.
  5.  
  6.     OWL 1.1
  7.     Copyright (c) 1986, 1987, by Oakland Group, Inc.
  8.     ALL RIGHTS RESERVED.
  9.  
  10.     Revision History:
  11.     -----------------
  12.     11/22/87 jmd     Replaced line characters with octal escape sequences
  13.      7/27/88 jmd     Upgraded to new border stuff
  14.      9/12/88 jmd    Added in and out data
  15.     11/13/88 jmd    Upgraded to new border stuff
  16.     11/20/88 jmd    Added ID to obj struct
  17.     12/20/88 jmd    removed SETSIZE msg
  18.  
  19.      5/28/89 jmd    added Shadow support
  20. */
  21.  
  22. #include "oakhead.h"
  23. #include "disppriv.h"
  24. #include "strdecl.h"        /* for strwrap() */
  25. #include "bordobj.h"
  26. #include "bordod.h"
  27.  
  28.  
  29. #define OUTER_BOX    "\332\304\267\272\274\315\324\263"
  30. #define HZ_LINE        "\303\304\266"
  31. #define VT_LINE        "\263\263\263"
  32.  
  33. /* scroll light macros */
  34. #ifdef BORDER_CHARS
  35. #    define    uplight(flag)    ((flag) ? "\x1e" : " ")
  36. #    define    downlight(flag)    ((flag) ? "\x1f" : " ")
  37. #else
  38. #    define    uplight(flag)    ((flag) ? "*" : " ")
  39. #    define    downlight(flag)    ((flag) ? "*" : " ")
  40. #endif
  41.  
  42. /* border object data */
  43.  
  44. typedef struct {
  45.     border_od    bdd;              /* common object super class */
  46.     boolean      up;                /* up and down lights */
  47.     boolean        down;
  48.     int            theight;        /* title height */
  49.  
  50. } bdtitle_od;
  51.  
  52. int bd_title(objdata, msg, indata, outdata)
  53.     VOID *objdata;
  54.     int msg;
  55.     VOID *indata;                /* message input data */
  56.     VOID *outdata;                /* message output data */
  57. /*
  58.     This is the "title" border used by some C-scape library
  59.     routines.
  60.     It is a border with double lines on the right and lower
  61.     sides and single lines on the left and top sides.
  62.     There is a title and two "lights" (defined in bdf_struct).
  63.     The title is a string of varying length with '\n's at the 
  64.     end of each line.
  65.     The up light and down light are booleans.  They are 
  66.     designed to display up and down arrows to indicate whether or
  67.     not there is more text to display in the enclosed sed.
  68.     A TRUE value indicates that the light should be visible.
  69.  
  70.     Example:
  71.                     +---------------+
  72.                     | Title         |
  73.                     |---------------|
  74.     Up light ----->    |*|             |
  75.                     | |             |
  76.     Down light --->    |*|             |
  77.                     +---------------+
  78.  
  79. */
  80. {
  81.     bdtitle_od  *bdtitled;
  82.     ocbox         cbox;
  83.     ptd_struct     *ptd;
  84.     int             tw;
  85.     boolean         oldup, olddown;
  86.     boolean         left, right;        /* dummy values */
  87.     byte         attr;
  88.  
  89.     bdtitled = (bdtitle_od *)objdata;
  90.  
  91.     switch(msg) {
  92.     case OBJM_GETDATASIZE:
  93.         ((ogds_struct *) outdata)->odsize = sizeof(bdtitle_od);
  94.         ((ogds_struct *) outdata)->xdsize = sizeof(border_xd);
  95.         ((ogds_struct *) outdata)->id = ID_BDTITLE;
  96.         break;
  97.  
  98.     case OBJM_OPEN:
  99.         if (!border_DoRaw(&bdtitled->bdd, msg, indata, outdata)) {
  100.             return(FALSE);
  101.         }
  102.  
  103.         bdtitled->theight = 0;
  104.         bord_SetSides(bdtitled->bdd.win, - (bdtitled->theight + 1), -3, 1, 1);
  105.         break;
  106.  
  107.     case BDM_RESIZE:
  108.         /* our window has changed size, reset the scroll lights */
  109.         bord_GetLights(bdtitled->bdd.win, &bdtitled->up, &bdtitled->down, &left, &right);
  110.         break;
  111.  
  112.     case BDM_SETTITLE:
  113.         if (bdtitled->bdd.title != NULL) {
  114.             ofree(OA_BDTITLE, (VOID *) bdtitled->bdd.title);
  115.             bdtitled->bdd.title = NULL;
  116.         }
  117.  
  118.         if (indata == NULL) {
  119.             bord_SetSides(bdtitled->bdd.win, - (bdtitled->theight + 1), -3, 1, 1);
  120.             break;
  121.         }
  122.  
  123.         tw = bord_GetWidth(bdtitled->bdd.win) - 2;
  124.         if ((bdtitled->bdd.title = strwrap((char *) indata, &bdtitled->theight, tw)) == NULL) {
  125.             return(FALSE);
  126.         }
  127.  
  128.         /* add for line at bottom of title */
  129.         (bdtitled->theight)++;
  130.  
  131.         /* adjust the border size */
  132.         bord_SetSides(bdtitled->bdd.win, - (bdtitled->theight + 1), -3, 1, 1);
  133.         break;
  134.  
  135.     case BDM_SCROLL:
  136.         /* adjust the up and down lights */
  137.         oldup = bdtitled->up;
  138.         olddown = bdtitled->down;
  139.         bord_GetLights(bdtitled->bdd.win, &bdtitled->up, &bdtitled->down, &left, &right);
  140.  
  141.         /* Only paint if arrows have changed */
  142.         if (oldup != bdtitled->up || olddown != bdtitled->down) {
  143.             /* paint up arrow */
  144.             cbox.toprow   = 0;
  145.             cbox.leftcol  = -2;
  146.             cbox.botrow   = 0;
  147.             cbox.rightcol = -2;
  148.             win_PaintBox(bdtitled->bdd.win, &cbox);
  149.             
  150.             /* paint down arrow */
  151.             cbox.toprow   = win_GetHeight(bdtitled->bdd.win) - 1;
  152.             cbox.botrow   = cbox.toprow;
  153.             win_PaintBox(bdtitled->bdd.win, &cbox);
  154.         }
  155.         break;
  156.  
  157.     case BDM_SHADOW:
  158.     case BDM_DRAW:
  159.         /* draw the border */
  160.         ptd = (ptd_struct *)indata;
  161.  
  162.         attr = (msg == BDM_DRAW) ? 
  163.             bord_GetAttr(bdtitled->bdd.win) : win_GetShadowAttr(bdtitled->bdd.win);
  164.  
  165.         /* draw the outer box */
  166.         bord_GetBox(bdtitled->bdd.win, &cbox);
  167.         ptd_DrawCharBox(ptd, OUTER_BOX, &cbox, attr);
  168.  
  169.         /* draw the vertical bars */
  170.         cbox.toprow   = 0;
  171.         cbox.leftcol  = -1;
  172.         cbox.botrow   = win_GetHeight(bdtitled->bdd.win) - 1;
  173.         cbox.rightcol = -1;
  174.         ptd_DrawCharLine(ptd, VT_LINE, &cbox, attr);
  175.  
  176.         cbox.leftcol  = -2;        /* top and bottom don't change */
  177.         cbox.rightcol = -2;
  178.         ptd_DrawCharLine(ptd, "   ", &cbox, attr);
  179.         
  180.         /* draw the scroll lights */
  181.         /* uplight */
  182.         ptd_DrawString(ptd, 0, -2, uplight(bdtitled->up), attr, 1);
  183.         /* downlight */
  184.         ptd_DrawString(ptd, cbox.botrow, -2, downlight(bdtitled->down), attr, 1);
  185.  
  186.         /* draw the title if there is one */
  187.         if (bdtitled->bdd.title != NULL) {
  188.             /* draw the horizontal bar */
  189.             cbox.toprow   = -1;
  190.             cbox.leftcol  = -3;
  191.             cbox.botrow   = cbox.toprow;
  192.             cbox.rightcol = win_GetWidth(bdtitled->bdd.win);
  193.             ptd_DrawCharLine(ptd, HZ_LINE, &cbox, attr);
  194.  
  195.             tw = win_GetWidth(bdtitled->bdd.win) + 2;
  196.             bord_DrawTitle(ptd, -bdtitled->theight, -2, bdtitled->bdd.title, attr, tw);
  197.         }
  198.         /* else no break; pass message up to superclass */
  199.  
  200.     default:
  201.         return(border_DoRaw(&bdtitled->bdd, msg, indata, outdata));
  202.     }
  203.     return(1);
  204. }
  205.  
  206.