home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / BDPROMPT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  3.9 KB  |  142 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.1
  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.  
  18. #include "oakhead.h"
  19. #include "disppriv.h"
  20. #include "strdecl.h"
  21.  
  22. #include "bordobj.h"
  23. #include "bdpromod.h"
  24.  
  25. #define OUTER_BOX    "\332\304\277\263\331\304\300\263"
  26.  
  27. enum action_flag          { ACT_NO, ACT_SCROLL, ACT_MOVE, 
  28.                            ACT_SIZE1, ACT_SIZE2, ACT_SIZE3, ACT_SIZE4 };
  29. /* -------------------------------------------------------------------------- */
  30.  
  31. int bd_prompt(objdata, msg, indata, outdata)
  32.     VOID *objdata;
  33.     int msg;
  34.     VOID *indata;                /* message input data */
  35.     VOID *outdata;                /* message output data */
  36. /*
  37.     This is a simple single lined border with an overwritten title and prompt.
  38.     The title is pointed to by the border data pointer.
  39.     Example:
  40.                      +-----Title-----+
  41.                      |               |
  42.                      |               |
  43.                      |               |
  44.                      |               |
  45.                      +Prompt---------+
  46. */
  47. {
  48.     bdprompt_od *bdpromod;
  49.     ocbox        cbox;           
  50.     ptd_struct *ptd;
  51.     char        *p;
  52.     int            width;
  53.     byte        attr;
  54.  
  55.     bdpromod = (bdprompt_od *)objdata;
  56.  
  57.     switch(msg) {
  58.     case OBJM_GETDATASIZE:
  59.         ((ogds_struct *) outdata)->odsize = sizeof(bdprompt_od);
  60.         ((ogds_struct *) outdata)->xdsize = sizeof(border_xd);
  61.         ((ogds_struct *) outdata)->id = ID_BDPROMPT;
  62.         break;
  63.  
  64.     case OBJM_OPEN:
  65.         if (!border_DoRaw(&bdpromod->bdd, msg, indata, outdata)) {
  66.             return(FALSE);
  67.         }
  68.         bdpromod->prompt[0] = '\0';
  69.  
  70.         bord_SetSides(bdpromod->bdd.win, -1, -1, 1, 1);
  71.         /* No break; fall through to set size */
  72.  
  73.     case BDM_RESIZE:
  74.         /* Reset width of prompt and title */
  75.         width = win_GetWidth(bdpromod->bdd.win);
  76.         bdpromod->plen = int_min(width, strlen(bdpromod->prompt));
  77.         bdpromod->tlen = int_min(width, 
  78.                     ((bdpromod->bdd.title == NULL) ? 0 : strlen(bdpromod->bdd.title)));
  79.         break;
  80.  
  81.     case BDM_SETTITLE:
  82.         if (bdpromod->bdd.title != NULL) {
  83.             ofree(OA_BDTITLE, (VOID *) bdpromod->bdd.title);
  84.             bdpromod->bdd.title = NULL;
  85.         }
  86.  
  87.         if (indata != NULL && (bdpromod->bdd.title = (char *) omalloc(OA_BDTITLE, strlen((char *)indata) + 1)) != NULL) {
  88.             strcpy(bdpromod->bdd.title, (char *) indata);
  89.             bdpromod->tlen = int_min(win_GetWidth(bdpromod->bdd.win), strlen(bdpromod->bdd.title));
  90.         }
  91.         break;
  92.  
  93.     case BDM_PROMPT:
  94.         /* set the border prompt string */
  95.         p = (indata != NULL) ? ((char *) indata) : "";
  96.  
  97.         /* Test if prompt has changed */
  98.         if (strcmp(p, bdpromod->prompt) != 0) {
  99.             strncpy(bdpromod->prompt, p, BD_PROMPTLEN);
  100.             bdpromod->prompt[BD_PROMPTLEN] = '\0';
  101.             bdpromod->plen = int_min(win_GetWidth(bdpromod->bdd.win), 
  102.                                         strlen(bdpromod->prompt));
  103.             /* Update the prompt */
  104.             cbox.toprow   = win_GetHeight(bdpromod->bdd.win);
  105.             cbox.leftcol  = 0;
  106.             cbox.botrow   = cbox.toprow;
  107.             cbox.rightcol = win_GetWidth(bdpromod->bdd.win) - 1;
  108.             win_PaintBox(bdpromod->bdd.win, &cbox);
  109.         }
  110.         break;
  111.  
  112.     case BDM_SHADOW:
  113.     case BDM_DRAW:
  114.         /* Draw the border */
  115.         ptd = (ptd_struct *)indata;
  116.         width = win_GetWidth(bdpromod->bdd.win);
  117.         attr = (msg == BDM_DRAW) ? 
  118.             bord_GetAttr(bdpromod->bdd.win) : win_GetShadowAttr(bdpromod->bdd.win);
  119.  
  120.         /* draw the box */
  121.         bord_GetBox(bdpromod->bdd.win, &cbox);
  122.         ptd_DrawCharBox(ptd, OUTER_BOX, &cbox, attr);
  123.  
  124.         /* Draw the title if there is one */
  125.         if (bdpromod->bdd.title != NULL) {
  126.             ptd_DrawString(ptd, -1, (width - bdpromod->tlen) / 2,
  127.                             bdpromod->bdd.title, attr, bdpromod->tlen);
  128.         }
  129.         /* Draw the prompt */
  130.         ptd_DrawString(ptd, win_GetHeight(bdpromod->bdd.win), 0,
  131.                         bdpromod->prompt, attr, bdpromod->plen);
  132.  
  133.         /* no break; pass message up to superclass */
  134.  
  135.     default:
  136.         return(border_DoRaw(&bdpromod->bdd, msg, indata, outdata));
  137.     }
  138.     return(1);
  139. }
  140. /* -------------------------------------------------------------------------- */
  141.  
  142.