home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / programm / libs / lib_coll.lha / FRQLIB.LZH / Programming.LZH / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-29  |  3.2 KB  |  123 lines

  1. /*
  2.  *  kd_freq.library NewFR() Test
  3.  *
  4.  *  This demonstrates the use of CreateFRequest(), DeleteFRequest() and
  5.  *  NewFReq() for a minimum of fuss in allocating stuff for the FR.
  6.  *
  7.  *  Note the use of  NextSelectEntry() to check the select list.
  8.  *
  9.  *  You need to assemble and link  glue.asm with this, or use the
  10.  *  appropriate #pragmas!
  11.  *
  12.  */
  13.  
  14.  
  15. #include "KDBase.h"
  16.  
  17. struct Library *KD_FReqBase, *OpenLibrary();
  18.  
  19. struct ExtraButton eb = {
  20.     NULL,            /* pointer to next button, unused, set to NULL */
  21.     NULL,            /* button flags, unused, set to NULL */
  22.     NULL,            /* address of function to call, fill in later */
  23.     (UBYTE *)"My Button",    /* Text to appear on button, up to 10 chars */
  24.     (UBYTE *)"An Extra Button",    /* next 3 are help lines.. all are optional */
  25.     (UBYTE *)"for that special function",
  26.     (UBYTE *)"in your program",
  27.     NULL,            /* Your own data here. */
  28.     NULL            /* leave this empty */
  29.     };
  30.  
  31. ULONG button(eb)
  32.     struct ExtraButton *eb;
  33.     {
  34.     printf("Hey!  The user clicked on the extra button!!\n");
  35.  
  36.     printf("Button: %s\n",eb->text);
  37.     printf("Window: %08x\n",eb->window);
  38.  
  39.     return(EB_CONTINUE);
  40.     }
  41.  
  42. main()
  43.     {
  44.     struct FRequest *fr, *CreateFRequest();
  45.     char *file, *NewFReq();
  46.     UBYTE *entry, *NextSelectEntry();
  47.  
  48.     if (KD_FReqBase = OpenLibrary(KLIBNAME,KLIBVERSION))
  49.         {
  50.         if (fr = (struct FRequest *) CreateFRequest())
  51.             {
  52.             /* Set the requester title */
  53.             fr->reqtitle = (UBYTE *) "FR Test";
  54.  
  55.             /* already set by CreateFRequest() */
  56.             fr->flags = FR_STDFLAGS | FR_SELECTLIST | FR_EXTRABUTTONS | FR_USEPENS;
  57.  
  58.             /* We want to add our own button (gadget) to the FR */
  59.             fr->extras->button = &eb;
  60.         
  61.             /* Address of function to call when our extrabutton is clicked */
  62.             eb.button_function = button;
  63.  
  64.             /* Set the default show and hide wildcards */
  65.             /*    strcpy(fr->pattern,"#?.?"); */
  66.             /*    strcpy(fr->extras->Hide,"#?.o"); */
  67.  
  68.  
  69.             /* let's set up our own color scheme... */
  70.             /* in this case, we are using the default pens the FR normally uses */
  71.             /* If we don't do this, we must clear the FR_USEPENS flag above */
  72.  
  73.             fr->extras->pen0 = 1;    /* shadow pen */
  74.             fr->extras->pen1 = 1;    /* basic text pen for filenames */ 
  75.             fr->extras->pen2 = 2;    /* titles and info pen */
  76.             fr->extras->pen3 = 3;    /* directories pen */
  77.  
  78.             /* Call the file requester and get a file name */
  79.  
  80.             if (file = (char *)NewFReq(fr))    
  81.                 printf("Selected: %s\n\n",file);
  82.             else
  83.                 printf("Cancelled.\n\n");
  84.         
  85.             /* Show some of the stuff we got back from the call */
  86.  
  87.             printf("Path    : %s\n",fr->fullname);
  88.             printf("Title   : %s\n",fr->reqtitle);
  89.             printf("Dir     : %s\n",fr->directory);
  90.             printf("File    : %s\n",fr->filename);
  91.             printf("Show Pat: %s\n",fr->pattern);
  92.             printf("Hide Pat: %s\n",fr->extras->Hide);
  93.             printf("Position: %3d , %3d\n",fr->extras->LeftEdge,fr->extras->TopEdge);
  94.             printf("Size    : %3d x %3d\n",fr->extras->Width,fr->extras->Height);
  95.  
  96.  
  97.             /* Check if the user selected multiple files */
  98.         
  99.             if (fr->extras->SelectList)    
  100.                 {
  101.                 /* ok.. print them out */
  102.                 printf("\nSelect List:\n\n");
  103.  
  104.                 while (entry = NextSelectEntry(fr))
  105.                     {
  106.                     printf("%s\n",entry);
  107.                     }
  108.                 }
  109.  
  110.  
  111.             /* Don't do this unless you're done with the FRequest struct */
  112.  
  113.             DeleteFRequest(fr);
  114.             }
  115.  
  116.         CloseLibrary(KD_FReqBase);
  117.         }
  118.     else
  119.         {
  120.         printf("Can't Open 'kd_freq.library'.  Make sure it is in LIBS:\n");
  121.         }
  122.     }
  123.