home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12518.ZIP / BUTTON.C next >
C/C++ Source or Header  |  1989-10-12  |  3KB  |  115 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->title;
  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.  
  83.     if(*text)                                   // if title, write it
  84.         VioWrtCharStrAtt(text,strlen(text),row,startcol+2,&cell[1],VIOHDL);
  85.                                                 // write the left border
  86.     VioWrtCharStrAtt("║",1,++row,startcol,&cell[1],VIOHDL);
  87.     text = b->text;                             // reset pointer
  88.                                                 //
  89.                                                 // write the message
  90.     VioWrtCharStrAtt(text,strlen(text),row,startcol+1,&cell[1],VIOHDL);
  91.                                                 // write the right border  
  92.     VioWrtCharStrAtt("║",1,row,endcol,&cell[1],VIOHDL);
  93.                                                 // write the 3rd corner    
  94.     VioWrtCharStrAtt("╚",1,++row,startcol,&cell[1],VIOHDL);
  95.                                                 // write the bottom line   
  96.     VioWrtNCell(cell,len,row,startcol+1,VIOHDL);
  97.                                                 // write the 4th corner    
  98.     VioWrtCharStrAtt("╝",1,row,endcol,&cell[1],VIOHDL);
  99.     }
  100.  
  101.  
  102. void ButtonPaint(BUTTON *b, BYTE attribute)
  103.     {
  104.     USHORT    row = b->startrow;
  105.     USHORT    col = b->startcol;
  106.     USHORT    endrow = b->endrow;
  107.     USHORT    num = b->endcol-col+1;
  108.  
  109.     for( ; row <= endrow; row++)
  110.         VioWrtNAttr(&attribute,num,row,col,VIOHDL);
  111.     }
  112.  
  113.  
  114.  
  115.