home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / BDBOX.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-24  |  2.9 KB  |  114 lines

  1. /*
  2.     bdbox.c     11/19/87
  3.  
  4.     % single lined border with overwritten title routine.
  5.  
  6.     OWL 1.2
  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.     11/06/89 jmd    removed DoRaw macros
  22.      2/21/90 ted    Added SetCharSize(TRUE) because border won't work otherwise.
  23.      3/28/90 jmd    ansi-fied
  24.      9/24/90 jsm    added casts to (char *) for C++ 
  25. */
  26.  
  27. #include "oakhead.h"
  28. #include "disppriv.h"
  29. #include "bordobj.h"
  30. #include "bordod.h"
  31.  
  32. #define OUTER_BOX    "\332\304\277\263\331\304\300\263"
  33.  
  34. /* border object data */
  35.  
  36. typedef struct _bdboxod {
  37.     border_od    bdd;              /* common object super class */
  38. } bdbox_od;
  39.  
  40. int bd_box(VOID *objdata, int msg, VOID *indata, VOID *outdata)
  41. /*
  42.     This is a simple single lined border.
  43.     With an overwritten title.
  44.     The title is pointed to by the border data pointer.
  45.     Example:
  46.                     +-----Title-----+
  47.                     |               |
  48.                     |               |
  49.                     |               |
  50.                     |               |
  51.                     +---------------+
  52. */
  53. {
  54.     bdbox_od     *bdboxd;
  55.     ocbox         cbox;
  56.     ptd_struct     *ptd;
  57.     int          len, tw;
  58.     byte         attr;
  59.  
  60.     bdboxd = (bdbox_od *)objdata;
  61.  
  62.     switch(msg) {
  63.     case OBJM_GETDATASIZE:
  64.         ((ogds_struct *) outdata)->odsize = sizeof(bdbox_od);
  65.         ((ogds_struct *) outdata)->xdsize = sizeof(border_xd);
  66.         ((ogds_struct *) outdata)->id = ID_BDBOX;
  67.         break;
  68.  
  69.     case OBJM_OPEN:
  70.         if (!border_Class(&bdboxd->bdd, msg, indata, outdata)) {
  71.             return(FALSE);
  72.         }
  73.         win_SetCharSize(bdboxd->bdd.win, TRUE);    /* This bord must be charsize */
  74.         bord_SetSides(bdboxd->bdd.win, -1, -1, 1, 1);
  75.         break;
  76.  
  77.     case BDM_SETTITLE:
  78.         if (bdboxd->bdd.title != NULL) {
  79.             ofree(OA_BDTITLE, (VOID *) bdboxd->bdd.title);
  80.             bdboxd->bdd.title = NULL;
  81.         }
  82.  
  83.         if (indata != NULL && (bdboxd->bdd.title = (char *) omalloc(OA_BDTITLE, strlen((char *)indata) + 1)) != NULL) {
  84.             strcpy(bdboxd->bdd.title, (char *) indata);
  85.         }
  86.         break;
  87.  
  88.     case BDM_SHADOW:
  89.     case BDM_DRAW:
  90.         /* draw the border */
  91.         ptd = (ptd_struct *)indata;
  92.  
  93.         attr = (msg == BDM_DRAW) ? 
  94.             bord_GetAttr(bdboxd->bdd.win) : win_GetShadowAttr(bdboxd->bdd.win);
  95.  
  96.         /* draw the box */
  97.         bord_GetBox(bdboxd->bdd.win, &cbox);
  98.         ptd_DrawCharBox(ptd, OUTER_BOX, &cbox, attr);
  99.  
  100.         /* draw the title if there is one */
  101.         if (bdboxd->bdd.title != NULL) {
  102.             tw = win_GetWidth(bdboxd->bdd.win);
  103.             len = strlen(bdboxd->bdd.title);
  104.             len = (len > tw) ? tw : len;
  105.             ptd_DrawString(ptd, -1, (tw - len) / 2, bdboxd->bdd.title, attr, len);
  106.         }
  107.         /* else no break; pass message up to superclass */
  108.  
  109.     default:
  110.         return(border_Class(&bdboxd->bdd, msg, indata, outdata));
  111.     }
  112.     return(1);
  113. }
  114.