home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / BDPROMPT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-13  |  4.2 KB  |  146 lines

  1. /*
  2.     bdprompt.c    12/16/88
  3.  
  4.     % box border with title and prompt
  5.  
  6.     12/19/88  by Ted.
  7.     Extracted from bdmouse for the purpose of inheriting it back in.
  8.  
  9.     OWL 1.2
  10.     Copyright (c) 1988, 1989 by Oakland Group, Inc.
  11.     ALL RIGHTS RESERVED.
  12.  
  13.     Revision History:
  14.     -----------------
  15.      5/28/89 jmd    added Shadow support
  16.  
  17.     11/06/89 jmd    removed DoRaw macros
  18.      2/21/90 ted    Added SetCharSize(TRUE) because border won't work otherwise.
  19.      3/28/90 jmd    ansi-fied
  20.      4/09/90 pmcm    altered cbox in BDM_DRAW to accomodate subclass bd_mouse2.
  21.  
  22. */
  23.  
  24. #include "oakhead.h"
  25. #include "disppriv.h"
  26. #include "strdecl.h"
  27.  
  28. #include "bordobj.h"
  29. #include "bdpromod.h"
  30.  
  31. #define OUTER_BOX    "\332\304\277\263\331\304\300\263"
  32.  
  33. enum action_flag          { ACT_NO, ACT_SCROLL, ACT_MOVE, 
  34.                            ACT_SIZE1, ACT_SIZE2, ACT_SIZE3, ACT_SIZE4 };
  35. /* -------------------------------------------------------------------------- */
  36.  
  37. int bd_prompt(VOID *objdata, int msg, VOID *indata, VOID *outdata)
  38. /*
  39.     This is a simple single lined border with an overwritten title and prompt.
  40.     The title is pointed to by the border data pointer.
  41.     Example:
  42.                      +-----Title-----+
  43.                      |               |
  44.                      |               |
  45.                      |               |
  46.                      |               |
  47.                      +Prompt---------+
  48. */
  49. {
  50.     bdprompt_od *bdpromod;
  51.     ocbox        cbox;           
  52.     ptd_struct *ptd;
  53.     char        *p;
  54.     int            width;
  55.     byte        attr;
  56.  
  57.     bdpromod = (bdprompt_od *)objdata;
  58.  
  59.     switch(msg) {
  60.     case OBJM_GETDATASIZE:
  61.         ((ogds_struct *) outdata)->odsize = sizeof(bdprompt_od);
  62.         ((ogds_struct *) outdata)->xdsize = sizeof(border_xd);
  63.         ((ogds_struct *) outdata)->id = ID_BDPROMPT;
  64.         break;
  65.  
  66.     case OBJM_OPEN:
  67.         if (!border_Class(&bdpromod->bdd, msg, indata, outdata)) {
  68.             return(FALSE);
  69.         }
  70.         bdpromod->prompt[0] = '\0';
  71.  
  72.         win_SetCharSize(bdpromod->bdd.win, TRUE);    /* This bord must be charsize */
  73.         bord_SetSides(bdpromod->bdd.win, -1, -1, 1, 1);
  74.         /* No break; fall through to set size */
  75.  
  76.     case BDM_RESIZE:
  77.         /* Reset width of prompt and title */
  78.         width = win_GetWidth(bdpromod->bdd.win);
  79.         bdpromod->plen = int_min(width, strlen(bdpromod->prompt));
  80.         bdpromod->tlen = int_min(width, 
  81.                     ((bdpromod->bdd.title == NULL) ? 0 : strlen(bdpromod->bdd.title)));
  82.         break;
  83.  
  84.     case BDM_SETTITLE:
  85.         if (bdpromod->bdd.title != NULL) {
  86.             ofree(OA_BDTITLE, (VOID *) bdpromod->bdd.title);
  87.             bdpromod->bdd.title = NULL;
  88.         }
  89.  
  90.         if (indata != NULL && (bdpromod->bdd.title = (char *) omalloc(OA_BDTITLE, strlen((char *)indata) + 1)) != NULL) {
  91.             strcpy(bdpromod->bdd.title, (char *) indata);
  92.             bdpromod->tlen = int_min(win_GetWidth(bdpromod->bdd.win), strlen(bdpromod->bdd.title));
  93.         }
  94.         break;
  95.  
  96.     case BDM_PROMPT:
  97.         /* set the border prompt string */
  98.         p = (indata != NULL) ? ((char *) indata) : "";
  99.  
  100.         /* Test if prompt has changed */
  101.         if (strcmp(p, bdpromod->prompt) != 0) {
  102.             strncpy(bdpromod->prompt, p, BD_PROMPTLEN);
  103.             bdpromod->prompt[BD_PROMPTLEN] = '\0';
  104.             bdpromod->plen = int_min(win_GetWidth(bdpromod->bdd.win), 
  105.                                         strlen(bdpromod->prompt));
  106.             /* Update the prompt */
  107.             cbox.toprow   = win_GetHeight(bdpromod->bdd.win);
  108.             cbox.leftcol  = 0;
  109.             cbox.botrow   = cbox.toprow;
  110.             cbox.rightcol = win_GetWidth(bdpromod->bdd.win) - 1;
  111.             win_PaintBox(bdpromod->bdd.win, &cbox);
  112.         }
  113.         break;
  114.  
  115.     case BDM_SHADOW:
  116.     case BDM_DRAW:
  117.         /* Draw the border */
  118.         ptd = (ptd_struct *)indata;
  119.         width = win_GetWidth(bdpromod->bdd.win);
  120.         attr = (msg == BDM_DRAW) ? 
  121.             bord_GetAttr(bdpromod->bdd.win) : win_GetShadowAttr(bdpromod->bdd.win);
  122.  
  123.         /* draw the box */
  124.         bord_GetBox(bdpromod->bdd.win, &cbox);
  125.         cbox.botrow = win_GetHeight(bdpromod->bdd.win);
  126.         ptd_DrawCharBox(ptd, OUTER_BOX, &cbox, attr);
  127.  
  128.         /* Draw the title if there is one */
  129.         if (bdpromod->bdd.title != NULL) {
  130.             ptd_DrawString(ptd, -1, (width - bdpromod->tlen) / 2,
  131.                             bdpromod->bdd.title, attr, bdpromod->tlen);
  132.         }
  133.         /* Draw the prompt */
  134.         ptd_DrawString(ptd, win_GetHeight(bdpromod->bdd.win), 0,
  135.                         bdpromod->prompt, attr, bdpromod->plen);
  136.  
  137.         /* no break; pass message up to superclass */
  138.  
  139.     default:
  140.         return(border_Class(&bdpromod->bdd, msg, indata, outdata));
  141.     }
  142.     return(1);
  143. }
  144. /* -------------------------------------------------------------------------- */
  145.  
  146.