home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12442.ZIP / BUTTON.C next >
C/C++ Source or Header  |  1989-07-31  |  2KB  |  110 lines

  1. /* button.c RHS 7/15/89
  2.  *
  3.  * text-button functions
  4.  */
  5.  
  6. #define    INCL_SUB
  7. #include<os2.h>
  8. #include<string.h>
  9. #include"button.h"
  10.  
  11. #define    VIOHDL                0
  12.  
  13. extern BUTTON buttonlist[];
  14.  
  15.  
  16. void InitButtons(void)
  17.     {
  18.     BUTTON *b = buttonlist;
  19.  
  20.     for( ; b->text; b++)
  21.         ButtonInit(b);
  22.     }
  23.  
  24.  
  25. void ButtonInit(BUTTON *b)
  26.     {
  27.     b->endrow = (b->startrow+2);                 /* startrow+#of ptrs-1     */
  28.                                                             /* startcol+strlen of text-1*/
  29.     b->endcol = (b->startcol+strlen(b->text)+1);
  30.     }
  31.  
  32.  
  33. void ResetButtons(void)
  34.     {
  35.     BUTTON *b = buttonlist;
  36.  
  37.     for( ; b->text; b++)
  38.         {
  39.         b->state = 0;
  40.         ButtonPaint(b,b->attribute);
  41.         }
  42.     }
  43.  
  44. void findbutton(char *text,BUTTON **bptr)
  45.     {
  46.     BUTTON *b = buttonlist;
  47.  
  48.     for( ; b->text; b++)
  49.         if(!strncmp(b->text,text,strlen(text)))
  50.             {
  51.             *bptr = b;
  52.             return;
  53.             }
  54.     }
  55.  
  56. void DisplayButtons(void)
  57.     {
  58.     BUTTON *b = buttonlist;
  59.  
  60.     for( ; b->text; b++)
  61.         ButtonDisplay(b);
  62.     }
  63.  
  64. void ButtonDisplay(BUTTON *b)
  65.     {
  66.     BYTE    cell[2];
  67.     USHORT    row = b->startrow;
  68.     USHORT    endcol = b->endcol;
  69.     USHORT    startcol = b->startcol;
  70.     char    *text = b->text;
  71.  
  72.     USHORT    len = endcol - startcol - 1;
  73.  
  74.     cell[0] = '═';
  75.     cell[1] = b->attribute;
  76.                                                             /* write the 1st corner char*/
  77.     VioWrtCharStrAtt("╒",1,row,startcol,&cell[1],VIOHDL);
  78.                                                             /* write the top line      */
  79.     VioWrtNCell(cell,len,row,startcol+1,VIOHDL);
  80.                                                 /* write the 2nd corner char*/
  81.     VioWrtCharStrAtt("╕",1,row,endcol,&cell[1],VIOHDL);
  82.                                                             /* write the left border   */
  83.     VioWrtCharStrAtt("│",1,++row,startcol,&cell[1],VIOHDL);
  84.                                                               /* write the message       */
  85.     VioWrtCharStrAtt(text,strlen(text),row,startcol+1,&cell[1],VIOHDL);
  86.                                                               /* write the right border  */
  87.     VioWrtCharStrAtt("│",1,row,endcol,&cell[1],VIOHDL);
  88.                                                             /* write the 3rd corner    */
  89.     VioWrtCharStrAtt("╘",1,++row,startcol,&cell[1],VIOHDL);
  90.                                                             /* write the bottom line   */
  91.     VioWrtNCell(cell,len,row,startcol+1,VIOHDL);
  92.                                                             /* write the 4th corner    */
  93.     VioWrtCharStrAtt("╛",1,row,endcol,&cell[1],VIOHDL);
  94.     }
  95.  
  96.  
  97. void ButtonPaint(BUTTON *b, BYTE attribute)
  98.     {
  99.     USHORT    row = b->startrow;
  100.     USHORT    col = b->startcol;
  101.     USHORT    endrow = b->endrow;
  102.     USHORT    num = b->endcol-col+1;
  103.  
  104.     for( ; row <= endrow; row++)
  105.         VioWrtNAttr(&attribute,num,row,col,VIOHDL);
  106.     }
  107.  
  108.  
  109.  
  110.