home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / s12628.zip / BUTTON.C next >
C/C++ Source or Header  |  1990-07-01  |  4KB  |  147 lines

  1. /* button.c RHS
  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],cell2[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] = 205;                      // line character
  75.     cell[1] = b->attribute;
  76.     cell2[1] = '\0';
  77.                                         // write the 1st corner char
  78.     cell2[0] = 201;
  79.     VioWrtCharStrAtt(cell2,1,row,startcol,&cell[1],VIOHDL); 
  80.                                         // write the top line
  81.     VioWrtNCell(cell,len,row,startcol+1,VIOHDL);
  82.                                         // write the 2nd corner char
  83.     cell2[0] = 187;
  84.     VioWrtCharStrAtt(cell2,1,row,endcol,&cell[1],VIOHDL);
  85.  
  86.     if(*text)                           // if title, write it
  87.         VioWrtCharStrAtt(text,strlen(text),row,startcol+2,&cell[1],
  88.             VIOHDL);
  89.                                         // write the left border
  90.     cell2[0] = 186;
  91.     VioWrtCharStrAtt(cell2,1,++row,startcol,&cell[1],VIOHDL);
  92.     text = b->text;                     // reset pointer
  93.                                         //
  94.                                         // write the message
  95.     VioWrtCharStrAtt(text,strlen(text),row,startcol+1,&cell[1],
  96.         VIOHDL);
  97.                                         // write the right border  
  98.     VioWrtCharStrAtt(cell2,1,row,endcol,&cell[1],VIOHDL);
  99.                                         // write the 3rd corner    
  100.     cell2[0] = 200;
  101.     VioWrtCharStrAtt(cell2,1,++row,startcol,&cell[1],VIOHDL);
  102.                                         // write the bottom line   
  103.     VioWrtNCell(cell,len,row,startcol+1,VIOHDL);
  104.                                         // write the 4th corner    
  105.     cell2[0] = 188;
  106.     VioWrtCharStrAtt(cell2,1,row,endcol,&cell[1],VIOHDL);
  107.     }
  108.  
  109.  
  110. void ButtonPaint(BUTTON *b, BYTE attribute)
  111.     {
  112.     USHORT    row = b->startrow;
  113.     USHORT    col = b->startcol;
  114.     USHORT    endrow = b->endrow;
  115.     USHORT    num = b->endcol-col+1;
  116.  
  117.     for( ; row <= endrow; row++)
  118.         VioWrtNAttr(&attribute,num,row,col,VIOHDL);
  119.     }
  120.  
  121.  
  122. void ButtonRead(BUTTON *b,char *contents)
  123.     {
  124.     int len = b->endcol - b->startcol - 1;
  125.  
  126.     VioReadCharStr((PCH)contents,&len,b->startrow+1,b->startcol+1,
  127.         VIOHDL);
  128.     contents[len] = '\0';
  129.     for(len--; len >= 0 && contents[len]==' '; len--);
  130.     len++;
  131.     contents[len] = '\0';
  132.     }
  133.  
  134. BUTTON *IsButton(USHORT row, USHORT col)
  135.     {
  136.     BUTTON *b = buttonlist;
  137.  
  138.     for( ; b->text; b++)
  139.         if(row >= b->startrow
  140.             && row <= b->endrow
  141.             && col >= b->startcol
  142.             && col <= b->endcol)
  143.             return b;
  144.     return NULL;
  145.     }
  146.  
  147.