home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / BDHEAD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-23  |  2.7 KB  |  119 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.2
  7.     Copyright (c) 1989, by Oakland Group, Inc.
  8.     ALL RIGHTS RESERVED.
  9.  
  10.     Revision History:
  11.     -----------------
  12.     11/06/89 jmd    removed DoRaw macros
  13.      2/21/90 ted    Added SetCharSize(TRUE) because border won't work otherwise.
  14.      3/28/90 jmd    ansi-fied
  15. */
  16.  
  17. #include "oakhead.h"
  18. #include "disppriv.h"
  19. #include "bordobj.h"
  20. #include "bordod.h"
  21.  
  22. #define HZ_LINE        "\304\304\304"
  23.  
  24. /* border object data */
  25.  
  26. typedef struct _bdheadod {
  27.     border_od    bdd;              /* common object super class */
  28. } bdhead_od;
  29.  
  30. int bd_head(VOID *objdata, int msg, VOID *indata, VOID *outdata)
  31. /*
  32.     This is a simple single lined border.
  33.     With an overwritten title.
  34.     The title is pointed to by the border data pointer.
  35.     Example:
  36.                           Title
  37.                     -----------------
  38. */
  39. {
  40.     bdhead_od     *bdheadd;
  41.     ocbox         cbox;
  42.     ptd_struct     *ptd;
  43.     int          len;
  44.     byte         attr;
  45.  
  46.     bdheadd = (bdhead_od *)objdata;
  47.  
  48.     switch(msg) {
  49.     case OBJM_GETDATASIZE:
  50.         ((ogds_struct *) outdata)->odsize = sizeof(bdhead_od);
  51.         ((ogds_struct *) outdata)->xdsize = sizeof(border_xd);
  52.         ((ogds_struct *) outdata)->id = ID_BDHEAD;
  53.         break;
  54.  
  55.     case OBJM_OPEN:
  56.         if (!border_Class(&bdheadd->bdd, msg, indata, outdata)) {
  57.             return(FALSE);
  58.         }
  59.  
  60.         win_SetCharSize(bdheadd->bdd.win, TRUE);    /* This bord must be charsize */
  61.         bord_SetSides(bdheadd->bdd.win, -2, 0, 0, 0);
  62.         break;
  63.  
  64.     case BDM_SETTITLE:
  65.         if (bdheadd->bdd.title != NULL) {
  66.             ofree(OA_BDTITLE, (VOID *) bdheadd->bdd.title);
  67.             bdheadd->bdd.title = NULL;
  68.         }
  69.  
  70.         if (indata != NULL) {
  71.             len = strlen((char *) indata);
  72.             if ((bdheadd->bdd.title = (char *) omalloc(OA_BDTITLE, len + 2)) == NULL) {
  73.                 return(FALSE);
  74.             }
  75.             strcpy(bdheadd->bdd.title, (char *) indata);
  76.  
  77.             /* get rid of '\n' if there is one */
  78.             if (len > 0 && bdheadd->bdd.title[len-1] == '\n') {
  79.                 bdheadd->bdd.title[len-1] = '\0';
  80.             }
  81.         }
  82.         else {
  83.             bdheadd->bdd.title = NULL;
  84.         }
  85.         break;
  86.  
  87.     case BDM_SHADOW:
  88.     case BDM_DRAW:
  89.         ptd = (ptd_struct *)indata;
  90.  
  91.         attr = (msg == BDM_DRAW) ? 
  92.             bord_GetAttr(bdheadd->bdd.win) : win_GetShadowAttr(bdheadd->bdd.win);
  93.  
  94.         /* Draw the title */
  95.  
  96.         ptd_DrawString(ptd,
  97.                        -2,
  98.                         0,
  99.                         (bdheadd->bdd.title == NULL) ? "" : bdheadd->bdd.title,
  100.                         attr,
  101.                         win_GetWidth(bdheadd->bdd.win));
  102.  
  103.  
  104.         /* Draw the horizontal lines */
  105.         cbox.toprow   = -1;
  106.         cbox.leftcol  = 0;
  107.         cbox.botrow   = cbox.toprow;
  108.         cbox.rightcol = win_GetWidth(bdheadd->bdd.win) - 1;
  109.         ptd_DrawCharLine(ptd, HZ_LINE, &cbox, attr);
  110.  
  111.         /* else no break; pass message up to superclass */
  112.  
  113.     default:
  114.         return(border_Class(&bdheadd->bdd, msg, indata, outdata));
  115.     }
  116.     return(1);
  117. }
  118.  
  119.