home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 428_02 / libsrc / multedit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-13  |  2.3 KB  |  106 lines

  1. /*
  2. ** multedit.c
  3. **
  4. ** Pictor, Version 1.51, Copyright (c) 1992-94 SoftCircuits
  5. ** Redistributed by permission.
  6. */
  7.  
  8. #include "pictor.h"
  9.  
  10.  
  11. #define MAX_LINES 10
  12. extern int _PL_tabendedit;
  13. extern int _PL_editfill;
  14.  
  15. /*
  16. ** Displays a window with mutiple edit fields. kbdedit is used for
  17. ** editing each field. The user can tab between the different fields.
  18. ** Returns TRUE if the user presses Enter, FALSE if Escape.
  19. */
  20. int multiedit(MEDITSTRUCT *items,int numitems,char *title,
  21.     COLORSTRUCT *colors)
  22. {
  23.     int i,j,maxprompt = 0,maxlen = 0,done = FALSE;
  24.     int top,left,height,width,editcol,curritem,retval = 0;
  25.  
  26.     if(numitems == 0) return(FALSE);
  27.     if(numitems > MAX_LINES) numitems = MAX_LINES;
  28.  
  29.     for(i = 0;i < numitems;i++) {
  30.         if((int)strlen(items[i].prompt) > maxprompt)
  31.             maxprompt = strlen(items[i].prompt);
  32.         if(items[i].maxlen > maxlen)
  33.             maxlen = items[i].maxlen;
  34.     }
  35.     maxlen++;
  36.     width = maxprompt + maxlen + 6;
  37.     i = width - (_PL_columns - 10);
  38.     if(i > 0) {
  39.         maxlen -= i;
  40.         width -= i;
  41.     }
  42.     height = (numitems * 2) + 1;
  43.  
  44.     top = center(height + 2,_PL_rows);
  45.     left = center(width + 2,_PL_columns);
  46.  
  47.     editcol = left + maxprompt + 5;
  48.  
  49.     if(!wopen(top,left,height + 2,width + 2,colors->normal,WO_SHADOW)) {
  50.         messagebox("Insufficient memory",title,MB_OK,colors);
  51.         return(FALSE);
  52.     }
  53.     wtitle(title);
  54.  
  55.     for(i = 0;i < numitems;i++) {
  56.  
  57.         /* prompt */
  58.         setwpos(2 + (i * 2),(maxprompt + 2) - strlen(items[i].prompt));
  59.         wputs(items[i].prompt);
  60.  
  61.         /* vcolor(colors->normal); */
  62.         setvpos(top + 2 + (i * 2),editcol - 3);
  63.         vputs(": [");
  64.  
  65.         for(j = 0;j < maxlen;j++) {
  66.             if(j < (int)strlen(items[i].buffer))
  67.                 vputc(items[i].buffer[j]);
  68.             else
  69.                 vputc((char)_PL_editfill);
  70.         }
  71.         vcolor(colors->normal);
  72.         vputc(']');
  73.     }
  74.  
  75.     _PL_tabendedit = TRUE;
  76.     curritem = 0;
  77.  
  78.     while(!done) {
  79.         switch(kbdedit(items[curritem].buffer,top + 2 + (curritem * 2),
  80.             editcol,maxlen,items[curritem].maxlen,colors)) {
  81.  
  82.             case -1:    /* tab */
  83.                 if(++curritem >= numitems)
  84.                     curritem = 0;
  85.                 break;
  86.             case -2:    /* shift-tab */
  87.                 if(--curritem < 0)
  88.                     curritem = (numitems - 1);
  89.                 break;
  90.             case 0:     /* escape */
  91.                 retval = FALSE;
  92.                 done = TRUE;
  93.                 break;
  94.             default:    /* return */
  95.                 retval = TRUE;
  96.                 done = TRUE;
  97.                 break;
  98.         }
  99.     }
  100.     _PL_tabendedit = FALSE;
  101.     wclose();
  102.  
  103.     return(retval);
  104.  
  105. } /* multiedit */
  106.