home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / i-7 / filehook.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  5KB  |  146 lines

  1. ;/* filehook.c - Execute me to compile me with SAS/C 6.56
  2. sc DATA=NEAR NMINC STRMERGE STREQ NOSTKCHK SAVEDS IGNORE=73 filehook.c
  3. slink FROM LIB:c.o,filehook.o TO filehook LIBRARY LIB:sc.lib,LIB:amiga.lib
  4. quit
  5. */
  6. /*
  7. Copyright (c) 1991 Commodore-Amiga, Inc.
  8.  
  9. This example is provided in electronic form by Commodore-Amiga,
  10. Inc. for use with the Amiga Mail Volume II technical publication.
  11. Amiga Mail Volume II contains additional information on the correct
  12. usage of the techniques and operating system functions presented in
  13. these examples.  The source and executable code of these examples may
  14. only be distributed in free electronic form, via bulletin board or
  15. as part of a fully non-commercial and freely redistributable
  16. diskette.  Both the source and executable code (including comments)
  17. must be included, without modification, in any copy.  This example
  18. may not be published in printed form or distributed with any
  19. commercial product. However, the programming techniques and support
  20. routines set forth in these examples may be used in the development
  21. of original executable software products for Commodore Amiga
  22. computers.
  23.  
  24. All other rights reserved.
  25.  
  26. This example is provided "as-is" and is subject to change; no
  27. warranties are made.  All use is at your own risk. No liability or
  28. responsibility is assumed.
  29. */
  30.  
  31.  
  32. #include <clib/asl_protos.h>
  33. #include <clib/exec_protos.h>
  34. #include <clib/dos_protos.h>
  35. #include <clib/intuition_protos.h>
  36. #include <clib/alib_stdio_protos.h>
  37. #include <dos/dosasl.h>
  38. #include <intuition/intuition.h>
  39. #include <exec/libraries.h>
  40.  
  41. #ifdef LATTICE
  42. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  43. int chkabort(void) { return(0); }  /* really */
  44. #endif
  45.  
  46. #define DESTPATLENGTH 20
  47.  
  48. UBYTE *vers = "\0$VER: filehook 1.0";
  49.  
  50. void main(void);
  51.  
  52. struct Library *AslBase;
  53. struct IntuitionBase *IntuitionBase;
  54. struct Window *window;
  55.  
  56. CPTR HookFunc();
  57.  
  58. /* this is the pattern matching string that the hook function uses */
  59. UBYTE *sourcepattern = "(#?.info)";
  60. UBYTE pat[DESTPATLENGTH];
  61.  
  62.  
  63. void main()
  64. {
  65.  
  66.     struct FileRequester *fr;
  67.  
  68.     /* This is a dos.library function that turns a pattern matching
  69.     ** string into something the DOS pattern matching functions
  70.     ** can understand.
  71.     */
  72.     ParsePattern(sourcepattern, pat, DESTPATLENGTH);
  73.  
  74.     if (AslBase = OpenLibrary("asl.library", 36L))
  75.     {
  76.         if (IntuitionBase = (struct IntuitionBase *)
  77.                     OpenLibrary("intuition.library", 36L))
  78.         {
  79.             /* open a window that gets ACTIVEWINDOW events */
  80.             if (window = (struct Window *)OpenWindowTags(NULL,
  81.                     WA_Title, "ASL Hook Function Example",
  82.                     WA_IDCMP, IDCMP_ACTIVEWINDOW,
  83.                     WA_Flags, WINDOWDEPTH,
  84.                     TAG_END))
  85.             {
  86.                 if (fr = AllocFileRequest())
  87.                 {
  88.                     /* application body here... */
  89.  
  90.  
  91.                     if (AslRequestTags(fr,
  92.                         ASL_Window, window,
  93.                         ASL_TopEdge, 0L,
  94.                         ASL_Height, 200L,
  95.                         ASL_Hail, (ULONG)"Pick an icon to save",
  96.                         ASL_HookFunc, (ULONG)HookFunc,
  97.                         ASL_FuncFlags, FILF_DOWILDFUNC | FILF_DOMSGFUNC | FILF_SAVE,
  98.                         ASL_OKText, (ULONG)"Save",
  99.                         TAG_DONE))
  100.                     {
  101.                         printf("You picked %s%s\n", fr->rf_Dir, fr->rf_File);
  102.                     }
  103.  
  104.                     /* more application body here */
  105.  
  106.                     FreeFileRequest(fr);
  107.                 }
  108.                 CloseWindow(window);
  109.             }
  110.             CloseLibrary(IntuitionBase);
  111.         }
  112.         CloseLibrary(AslBase);
  113.     }
  114. }
  115.  
  116.  
  117. CPTR HookFunc(LONG type, CPTR obj, struct FileRequester *fr)
  118. {
  119.     static BOOL returnvalue;
  120.     switch(type)
  121.     {
  122.         case FILF_DOMSGFUNC:
  123.         /* We got a message meant for the window */
  124.             printf("You activated the window\n");
  125.             return(obj);
  126.             break;
  127.         case FILF_DOWILDFUNC:
  128.         /* We got an AnchorPath structure, should
  129.         ** the requester display this file? */
  130.  
  131.             /* MatchPattern() is a dos.library function that
  132.             ** compares a matching pattern (parsed by the
  133.             ** ParsePattern() DOS function) to a string and
  134.             ** returns true if they match. */
  135.             returnvalue = MatchPattern(pat,
  136.                     ((struct AnchorPath *)obj)->ap_Info.fib_FileName);
  137.  
  138.             /* we have to negate MatchPattern()'s return value
  139.             ** because the file requester expects a zero for
  140.             ** a match not a TRUE value */
  141.             return( (CPTR)(! returnvalue) );
  142.             break;
  143.     }
  144. }
  145.  
  146.