home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / FSGFX.ZIP / G_FSELCT.C < prev    next >
C/C++ Source or Header  |  1990-03-07  |  5KB  |  186 lines

  1. /*  g_fselct.c */
  2. /*  simple file selector box    */
  3.  
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <dos.h>
  8.  
  9. #include "mygraph.h"
  10. #include "mymouse.h"
  11.  
  12. #define BSPACE  20   
  13. #define BHEIGHT 16
  14. #define FXSPOT 27*8
  15. #define FYSPOT 17*8
  16. #define FHSIZE 16*8
  17. #define MAXFILES 5
  18. #define FVSIZE MAXFILES*8 +6
  19.  
  20. static unsigned char sp[16][16] =
  21.     {  { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
  22.     { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
  23.     { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
  24.     { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
  25.     { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
  26.     { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
  27.     { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
  28.     { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
  29.     { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
  30.     { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
  31.     { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
  32.     { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 },
  33.     { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
  34.     { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
  35.     { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 },
  36.     { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 } };
  37. /*   { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15 }*/
  38.  
  39.  
  40. static struct _FILEFINDBUF dirlist[200];
  41. #define msstatus(b,x,y) if(MouEvent.fs & 0x06) b=1; else b=0; x = MouEvent.col; y = MouEvent.row; 
  42. int g_fselect(char searchpath[],char filename[])
  43. {
  44.     register int x,y;
  45.     int spot;
  46.     unsigned char uchar;
  47.     int filecount;
  48.     int done;
  49.     int a, b, c,z,bstat, offset, filenumber, selected;
  50.     char blank[13];
  51.  
  52.     int i = 0;
  53.     unsigned shan = -1;
  54.     int scnt = 1;
  55.  
  56.     strcpy(blank,"             ");
  57.     mshidecur();
  58.     msstatus(bstat,x,y);
  59.     mshbounds(x,x);
  60.     msvbounds(y,y);
  61.     if(!DosFindFirst(searchpath,&shan,_A_NORMAL,&dirlist[i],sizeof(dirlist[i]),&scnt,0L))
  62.     {
  63.         do i++;
  64.         while(DosFindNext(shan,&dirlist[i],sizeof(dirlist[i]),&scnt)==0);
  65.  
  66.     }    
  67.     DosFindClose(shan);
  68.     filecount = i;
  69.  
  70.     for(x = 0; x<FHSIZE; x++)
  71.     for(y = 0; y<FVSIZE+24; y++)
  72.         {
  73.         g_macrodoterase((FXSPOT+x),(FYSPOT-8+y));
  74.         }
  75.  
  76.     g_msgbox(FXSPOT,FYSPOT,FHSIZE,FVSIZE,searchpath,"");
  77.     g_line(FXSPOT+FHSIZE-22,FYSPOT,FXSPOT+FHSIZE-22,FYSPOT+FVSIZE);
  78.  
  79.     for (x = 0; x<16; x++)
  80.         for (y=0; y<16; y++)
  81.             if(sp[y][x] == 1)
  82.                 g_dot(FXSPOT+FHSIZE-20+x,y+FYSPOT+FVSIZE-18);
  83.  
  84.     for (x = 0; x<16; x++)
  85.         for (y=0; y<16; y++)
  86.             if(sp[y][x] == 1)
  87.                 g_dot(FXSPOT+FHSIZE-20+x,-y+FYSPOT+18);
  88.  
  89.     g_drwbtn(FXSPOT,FYSPOT+FVSIZE,"Ok","");
  90.     g_drwbtn(FXSPOT+FHSIZE-8*8,FYSPOT+FVSIZE,"Cancel","");
  91.  
  92.     msvbounds(0,SCR_YMAX-16);
  93.     mshbounds(0,SCR_XMAX-16);
  94.     for(a = 0; a < MAXFILES; a++)
  95.         g_puts(FXSPOT+8,(8*a)+FYSPOT+4,dirlist[a].achName);
  96.     msshowcur();
  97.     offset = 0;
  98.     done = 0;
  99.     selected = 0;
  100.     while( done >= 0)
  101.     {
  102.         bstat = 0;
  103.         msvbounds(0,342);
  104.         mshbounds(0,640);
  105.         while(bstat == 0 && !kbhit())
  106.             msstatus(bstat,x,y);
  107.         if(kbhit())
  108.             return(0);
  109.         if(x>FXSPOT && y > FYSPOT +FVSIZE && x < FXSPOT + 8*8
  110.             && y < FYSPOT + FVSIZE+BHEIGHT)
  111.         done = -1;
  112.  
  113.         if(x>FXSPOT+FHSIZE-8*8 && y > FYSPOT +FVSIZE && x < FXSPOT + FHSIZE
  114.             && y < FYSPOT + FVSIZE+BHEIGHT)
  115.         {
  116.             done = -1;
  117.             strcpy(filename,"");
  118.             selected = 0;
  119.         }
  120.  
  121.         if(x>FXSPOT && y > FYSPOT && x < FXSPOT + FHSIZE-24
  122.             && y < FYSPOT + FVSIZE)
  123.         {
  124.             a = (y-FYSPOT-4) / 8;
  125.             g_puts(FXSPOT,FYSPOT+FVSIZE+18,blank);
  126.             g_puts(FXSPOT,FYSPOT+FVSIZE+18,dirlist[a+offset].achName);
  127.             strcpy(filename,dirlist[a+offset].achName);
  128.             selected = -1;
  129.         }
  130.  
  131.         if(x>FXSPOT+FHSIZE-22 && y > FYSPOT && x < FXSPOT + FHSIZE
  132.             && y < FYSPOT + 20)
  133.         {
  134.             msvbounds(y,y);
  135.             mshbounds(x,x);
  136.             while(bstat == 1)
  137.             {
  138.                 offset--;
  139.                 if (offset < 0)
  140.                     offset = 0;
  141.                 for(a = 0; a < MAXFILES; a++)
  142.                 {
  143.                     g_puts(FXSPOT+8,(8*a)+FYSPOT+4,dirlist[a+offset].achName);
  144.                     c = strlen(dirlist[a+offset].achName);
  145.                     if(c< 12)
  146.                         for(x = 0; x <12-c; x++)
  147.                             g_puts(-1,-1," ");
  148.                 }
  149.             msstatus(bstat, x, y);
  150.             }
  151.         }
  152.  
  153.         if(x>FXSPOT+FHSIZE-22 && y > FYSPOT+FVSIZE-20 && x < FXSPOT + FHSIZE
  154.             && y < FYSPOT+FVSIZE)
  155.         {
  156.             msvbounds(y,y);
  157.             mshbounds(x,x);
  158.             while(bstat == 1)
  159.             {
  160.                 if(filenumber > MAXFILES)
  161.                     offset++;
  162.  
  163.                 if(offset > filenumber-MAXFILES && filenumber >= MAXFILES)
  164.                     offset = filenumber-MAXFILES;
  165.  
  166.                 for(a = 0; a < MAXFILES; a++)
  167.                 {
  168.                     g_puts(FXSPOT+8,(8*a)+FYSPOT+4,dirlist[a+offset].achName);
  169.                     c = strlen(dirlist[a+offset].achName);
  170.                     if(c< 12)
  171.                     for(x = 0; x <12-c; x++)
  172.                     g_puts(-1,-1," ");
  173.                 }
  174.             msstatus(bstat, x, y);
  175.             }
  176.         }
  177.  
  178.         while(bstat == 1)
  179.         msstatus(bstat,x,y);
  180.     }
  181.     if (selected < 0)
  182.         return -1;
  183.     else
  184.         return 0;
  185. }
  186.