home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / useful / dev / c / rkrm / workbench / iconexample.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  11KB  |  315 lines

  1. ;/* iconexample.c - Execute me to compile me with SAS C 5.10
  2. LC -b1 -cfistq -v -y -j73 iconexample.c
  3. Blink FROM LIB:c.o,iconexample.o TO iconexample LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit
  5. */
  6. /*
  7. Copyright (c) 1992 Commodore-Amiga, Inc.
  8.  
  9. This example is provided in electronic form by Commodore-Amiga, Inc. for
  10. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  11. published by Addison-Wesley (ISBN 0-201-56774-1).
  12.  
  13. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  14. information on the correct usage of the techniques and operating system
  15. functions presented in these examples.  The source and executable code
  16. of these examples may only be distributed in free electronic form, via
  17. bulletin board or as part of a fully non-commercial and freely
  18. redistributable diskette.  Both the source and executable code (including
  19. comments) must be included, without modification, in any copy.  This
  20. example may not be published in printed form or distributed with any
  21. commercial product.  However, the programming techniques and support
  22. routines set forth in these examples may be used in the development
  23. of original executable software products for Commodore Amiga computers.
  24.  
  25. All other rights reserved.
  26.  
  27. This example is provided "as-is" and is subject to change; no
  28. warranties are made.  All use is at your own risk. No liability or
  29. responsibility is assumed.
  30. */
  31. /*
  32. ** iconexample.c - Workbench icon startup, creation, and parsing example
  33. */
  34.  
  35. #include <exec/types.h>
  36. #include <libraries/dos.h>
  37. #include <workbench/workbench.h>
  38. #include <workbench/startup.h>
  39.  
  40. #include <clib/alib_protos.h>
  41. #include <clib/exec_protos.h>
  42. #include <clib/dos_protos.h>
  43. #include <clib/icon_protos.h>
  44. #include <stdlib.h>
  45. #include <stdio.h>
  46. #include <string.h>
  47.  
  48. #ifdef LATTICE
  49. int CXBRK(void) { return(0); }   /* Disable SAS Lattice CTRL/C handling */
  50. int chkabort(void) { return(0); }/* really */
  51. #endif
  52.  
  53. /* our functions */
  54. void cleanexit(UBYTE *,LONG);
  55. void cleanup(void);
  56. void message(UBYTE *);
  57. BOOL makeIcon(UBYTE *, char **, char *);
  58. BOOL showToolTypes(struct WBArg *);
  59.  
  60. UBYTE *projname     = "RAM:Example_Project";
  61. UBYTE *conwinname   = "CON:10/10/620/180/iconexample";
  62.  
  63. UBYTE deftoolname[] = {"iconexample"};
  64.  
  65. USHORT IconImageData1[] =  {
  66. /* Plane 0 */
  67.     0x0000,0x0000,0x0000,0x1000,0x0000,0x0000,0x0000,0x3000,
  68.     0x0FFF,0xFFFC,0x0000,0x3000,0x0800,0x0004,0x0000,0x3000,
  69.     0x0800,0x07FF,0xFFC0,0x3000,0x08A8,0xA400,0x00A0,0x3000,
  70.     0x0800,0x0400,0x0090,0x3000,0x08AA,0xA400,0x0088,0x3000,
  71.     0x0800,0x042A,0xA0FC,0x3000,0x082A,0xA400,0x0002,0x3000,
  72.     0x0800,0x0400,0x0002,0x3000,0x0800,0xA42A,0xA0A2,0x3000,
  73.     0x0800,0x0400,0x0002,0x3000,0x0950,0xA42A,0x8AA2,0x3000,
  74.     0x0800,0x0400,0x0002,0x3000,0x082A,0xA400,0x0002,0x3000,
  75.     0x0800,0x042A,0x2AA2,0x3000,0x0FFF,0xFC00,0x0002,0x3000,
  76.     0x0000,0x0400,0x0002,0x3000,0x0000,0x07FF,0xFFFE,0x3000,
  77.     0x0000,0x0000,0x0000,0x3000,0x7FFF,0xFFFF,0xFFFF,0xF000,
  78. /* Plane 1 */
  79.     0xFFFF,0xFFFF,0xFFFF,0xE000,0xD555,0x5555,0x5555,0x4000,
  80.     0xD000,0x0001,0x5555,0x4000,0xD7FF,0xFFF9,0x5555,0x4000,
  81.     0xD7FF,0xF800,0x0015,0x4000,0xD757,0x5BFF,0xFF55,0x4000,
  82.     0xD7FF,0xFBFF,0xFF65,0x4000,0xD755,0x5BFF,0xFF75,0x4000,
  83.     0xD7FF,0xFBD5,0x5F01,0x4000,0xD7D5,0x5BFF,0xFFFD,0x4000,
  84.     0xD7FF,0xFBFF,0xFFFD,0x4000,0xD7FF,0x5BD5,0x5F5D,0x4000,
  85.     0xD7FF,0xFBFF,0xFFFD,0x4000,0xD6AF,0x5BD5,0x755D,0x4000,
  86.     0xD7FF,0xFBFF,0xFFFD,0x4000,0xD7D5,0x5BFF,0xFFFD,0x4000,
  87.     0xD7FF,0xFBD5,0xD55D,0x4000,0xD000,0x03FF,0xFFFD,0x4000,
  88.     0xD555,0x53FF,0xFFFD,0x4000,0xD555,0x5000,0x0001,0x4000,
  89.     0xD555,0x5555,0x5555,0x4000,0x8000,0x0000,0x0000,0x0000,
  90. };
  91.  
  92. struct Image iconImage1 =
  93.     {
  94.     0, 0,                /* Top Corner */
  95.     52, 22, 2,           /* Width, Height, Depth */
  96.     &IconImageData1[0],  /* Image Data */
  97.     0x003, 0x000,        /* PlanePick,PlaneOnOff */
  98.     NULL                 /* Next Image */
  99.     };
  100.  
  101. UBYTE *toolTypes[] =
  102.     {
  103.     "FILETYPE=text",
  104.     "FLAGS=BOLD|ITALICS",
  105.     NULL
  106.     };
  107.  
  108. struct DiskObject projIcon =
  109.     {
  110.     WB_DISKMAGIC,                   /* Magic Number */
  111.     WB_DISKVERSION,                 /* Version */
  112.         {                           /* Embedded Gadget Structure */
  113.         NULL,                       /* Next Gadget Pointer */
  114.         97,12,52,23,                /* Left,Top,Width,Height */
  115.         GADGIMAGE|GADGHBOX,         /* Flags */
  116.         GADGIMMEDIATE|RELVERIFY,    /* Activation Flags */
  117.         BOOLGADGET,                 /* Gadget Type */
  118.         (APTR)&iconImage1,          /* Render Image */
  119.         NULL,                       /* Select Image */
  120.         NULL,                       /* Gadget Text */
  121.         NULL,                       /* Mutual Exclude */
  122.         NULL,                       /* Special Info */
  123.         0,                          /* Gadget ID */
  124.         NULL                        /* User Data */
  125.         },
  126.     WBPROJECT,                      /* Icon Type */
  127.     deftoolname,                    /* Default Tool */
  128.     toolTypes,                      /* Tool Type Array */
  129.     NO_ICON_POSITION,               /* Current X */
  130.     NO_ICON_POSITION,               /* Current Y */
  131.     NULL,                           /* Drawer Structure */
  132.     NULL,                           /* Tool Window */
  133.     4000                            /* Stack Size */
  134.     };
  135.  
  136. /* Opens and allocations we must clean up */
  137. struct Library *IconBase = NULL;
  138. FILE *conwin = NULL;
  139. LONG olddir = -1;
  140.  
  141. BOOL FromWb;
  142.  
  143. void main(int argc, char **argv)
  144.     {
  145.     struct WBStartup *WBenchMsg;
  146.     struct WBArg *wbarg;
  147.     FILE  *file;
  148.     LONG  wLen;
  149.     SHORT i;
  150.  
  151.     FromWb = (argc==0) ? TRUE : FALSE;
  152.  
  153.     /* Open icon.library */
  154.     if(!(IconBase = OpenLibrary("icon.library",33)))
  155.          cleanexit("Can't open icon.library\n",RETURN_FAIL);
  156.  
  157.     /* If started from CLI, this example will create a small text
  158.      * file RAM:Example_Project, and create an icon for the file
  159.      * which points to this program as its default tool.
  160.      */
  161.     if(!FromWb)
  162.         {
  163.         /* Make a sample project (data) file */
  164.         wLen = -1;
  165.         if(file=fopen(projname,"w"))
  166.             {
  167.             wLen = fprintf(file,"Have a nice day\n");
  168.             fclose(file);
  169.             }
  170.         if(wLen < 0) cleanexit("Error writing data file\n",RETURN_FAIL);
  171.  
  172.         /* Now save/update icon for this data file */
  173.         if(makeIcon(projname, toolTypes, deftoolname))
  174.              {
  175.              printf("%s data file and icon saved.\n",projname);
  176.              printf("Use Workbench menu Icon Information to examine the icon.\n");
  177.              printf("Then copy this example (iconexample) to RAM:\n");
  178.              printf("and double-click the %s project icon\n",projname);
  179.              }
  180.         else cleanexit("Error writing icon\n",RETURN_FAIL);
  181.         }
  182.  
  183.     else  /* Else we are FromWb - ie. we were either
  184.            * started by a tool icon, or as in this case,
  185.            * by being the default tool of a project icon.
  186.            */
  187.         {
  188.         if(!(conwin = fopen(conwinname,"r+")))
  189.              cleanexit("Can't open output window\n",RETURN_FAIL);
  190.  
  191.         WBenchMsg = (struct WBStartup *)argv;
  192.  
  193.         /* Note wbarg++ at end of FOR statement steps through wbargs.
  194.          * First arg is our executable (tool).  Any additional args
  195.          * are projects/icons passed to us via either extend select
  196.          * or default tool method.
  197.          */
  198.         for(i=0, wbarg=WBenchMsg->sm_ArgList;
  199.             i < WBenchMsg->sm_NumArgs;
  200.             i++, wbarg++)
  201.             {
  202.             /* if there's a directory lock for this wbarg, CD there */
  203.             olddir = -1;
  204.             if((wbarg->wa_Lock)&&(*wbarg->wa_Name))
  205.                 olddir = CurrentDir(wbarg->wa_Lock);
  206.  
  207.             showToolTypes(wbarg);
  208.  
  209.             if((i>0)&&(*wbarg->wa_Name))
  210.                 fprintf(conwin,"In Main. We could open the %s file here\n",
  211.                                  wbarg->wa_Name);
  212.             if(olddir != -1)  CurrentDir(olddir); /* CD back where we were */
  213.             }
  214.         Delay(500);
  215.         }
  216.     cleanup();
  217.     exit(RETURN_OK);
  218.     }
  219.  
  220. BOOL makeIcon(UBYTE *name, char **newtooltypes, char *newdeftool)
  221.     {
  222.     struct DiskObject *dobj;
  223.     char *