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

  1. /*
  2.     bdhead.c     8/24/89
  3.  
  4.     % a border with a title and line along the top and no side or bottom
  5.  
  6.     OWL 1.1
  7.     Copyright (c) 1989, by Oakland Group, Inc.
  8.     ALL RIGHTS RESERVED.
  9.  
  10.     Revision History:
  11.     -----------------
  12. */
  13.  
  14. #include "oakhead.h"
  15. #include "disppriv.h"
  16. #include "bordobj.h"
  17. #include "bordod.h"
  18.  
  19. #define HZ_LINE        "\304\304\304"
  20.  
  21. /* border object data */
  22.  
  23. typedef struct {
  24.     border_od    bdd;              /* common object super class */
  25. } bdhead_od;
  26.  
  27. int bd_head(objdata, msg, indata, outdata)
  28.     VOID *objdata;
  29.     int msg;
  30.     VOID *indata;                /* message input data */
  31.     VOID *outdata;                /* message output data */
  32. /*
  33.     This is a simple single lined border.
  34.     With an overwritten title.
  35.     The title is pointed to by the border data pointer.
  36.     Example:
  37.                           Title
  38.                     -----------------
  39.  
  40. */
  41. {
  42.     bdhead_od     *bdheadd;
  43.     ocbox         cbox;
  44.     ptd_struct     *ptd;
  45.     int          len;
  46.     byte         attr;
  47.  
  48.     bdheadd = (bdhead_od *)objdata;
  49.  
  50.     switch(msg) {
  51.     case OBJM_GETDATASIZE:
  52.         ((ogds_struct *) outdata)->odsize = sizeof(bdhead_od);
  53.         ((ogds_struct *) outdata)->xdsize = sizeof(border_xd);
  54.         ((ogds_struct *) outdata)->id = ID_BDHEAD;
  55.         break;
  56.  
  57.     case OBJM_OPEN:
  58.         if (!border_DoRaw(&bdheadd->bdd, msg, indata, outdata)) {
  59.             return(FALSE);
  60.         }
  61.  
  62.         bord_SetSides(bdheadd->bdd.win, -2, 0, 0, 0);
  63.         break;
  64.  
  65.     case BDM_SETTITLE:
  66.         if (bdheadd->bdd.title != NULL) {
  67.             ofree(OA_BDTITLE, (VOID *) bdheadd->bdd.title);
  68.             bdheadd->bdd.title = NULL;
  69.         }
  70.  
  71.         if (indata != NULL) {
  72.             len = strlen((char *) indata);
  73.             if ((bdheadd->bdd.title = (char *) omalloc(OA_BDTITLE, len + 2)) == NULL) {
  74.                 return(FALSE);
  75.             }
  76.             strcpy(bdheadd->bdd.title, (char *) indata);
  77.  
  78.             /* get rid of '\n' if there is one */
  79.             if (len > 0 && bdheadd->bdd.title[len-1] == '\n') {
  80.                 bdheadd->bdd.title[len-1] = '\0';
  81.             }
  82.         }
  83.         else {
  84.             bdheadd->bdd.title = NULL;
  85.         }
  86.         break;
  87.  
  88.     case BDM_SHADOW:
  89.     case BDM_DRAW:
  90.         ptd = (ptd_struct *)indata;
  91.  
  92.         attr = (msg == BDM_DRAW) ? 
  93.             bord_GetAttr(bdheadd->bdd.win) : win_GetShadowAttr(bdheadd->bdd.win);
  94.  
  95.         /* Draw the title */
  96.  
  97.         ptd_DrawString(ptd,
  98.                        -2,
  99.                         0,
  100.                         (bdheadd->bdd.title == NULL) ? "" : bdheadd->bdd.title,
  101.                         attr,
  102.                         win_GetWidth(bdheadd->bdd.win));
  103.  
  104.  
  105.         /* Draw the horizontal lines */
  106.         cbox.toprow   = -1;
  107.         cbox.leftcol  = 0;
  108.         cbox.botrow   = cbox.toprow;
  109.         cbox.rightcol = win_GetWidth(bdheadd->bdd.win) - 1;
  110.         ptd_DrawCharLine(ptd, HZ_LINE, &cbox, attr);
  111.  
  112.         /* else no break; pass message up to superclass */
  113.  
  114.     default:
  115.         return(border_DoRaw(&bdheadd->bdd, msg, indata, outdata));
  116.     }
  117.     return(1);
  118. }
  119.  
  120.