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

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