home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_3.5 / Examples / Icon / MakeIconsBorderless.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-30  |  5.3 KB  |  272 lines

  1. /*
  2.  * $Id$
  3.  *
  4.  * :ts=4
  5.  *
  6.  * COPYRIGHT:
  7.  *
  8.  *   Unless otherwise noted, all files are Copyright (c) 1999 Amiga, Inc.
  9.  *   All rights reserved.
  10.  *
  11.  * DISCLAIMER:
  12.  *
  13.  *   This software is provided "as is". No representations or warranties
  14.  *   are made with respect to the accuracy, reliability, performance,
  15.  *   currentness, or operation of this software, and all use is at your
  16.  *   own risk. Neither Amiga nor the authors assume any responsibility
  17.  *   or liability whatsoever with respect to your use of this software.
  18.  *
  19.  */
  20.  
  21. #include <dos/dosextens.h>
  22. #include <dos/dosasl.h>
  23. #include <dos/rdargs.h>
  24.  
  25. #include <exec/memory.h>
  26.  
  27. #include <workbench/workbench.h>
  28.  
  29. #include <clib/exec_protos.h>
  30. #include <clib/utility_protos.h>
  31. #include <clib/graphics_protos.h>
  32. #include <clib/dos_protos.h>
  33.  
  34. #include <pragmas/exec_sysbase_pragmas.h>
  35. #include <pragmas/utility_pragmas.h>
  36. #include <pragmas/graphics_pragmas.h>
  37. #include <pragmas/dos_pragmas.h>
  38.  
  39. #include <string.h>
  40.  
  41. /****************************************************************************/
  42.  
  43. extern struct Library * SysBase;
  44. extern struct Library * DOSBase;
  45. extern struct Library * UtilityBase;
  46. extern struct Library * GfxBase;
  47. extern struct Library * IconBase;
  48.  
  49. /****************************************************************************/
  50.  
  51. #include <workbench/icon.h>
  52. #include <clib/icon_protos.h>
  53. #include <pragmas/icon_pragmas.h>
  54.  
  55. /****************************************************************************/
  56.  
  57. #define OK (0)
  58. #define SAME (0)
  59.  
  60. /****************************************************************************/
  61.  
  62. #define MAX_PATH_LEN 1024
  63.  
  64. /****************************************************************************/
  65.  
  66. #define FIB_IS_DRAWER(fib)    ((fib)->fib_DirEntryType > 0)
  67. #define FIB_IS_FILE(fib)    ((fib)->fib_DirEntryType < 0)
  68.  
  69. /****************************************************************************/
  70.  
  71. UBYTE MagicWBPalette[8 * 3] =
  72. {
  73.     0x96,0x96,0x96,
  74.     0x00,0x00,0x00,
  75.     0xFF,0xFF,0xFF,
  76.     0x3D,0x65,0xA2,
  77.     0x79,0x79,0x79,
  78.     0xAE,0xAE,0xAE,
  79.     0xAA,0x92,0x7D,
  80.     0xFF,0xAA,0x96
  81. };
  82.  
  83. /****************************************************************************/
  84.  
  85. VOID
  86. ImageToBitMap(
  87.     struct Image *    image,
  88.     struct BitMap *    bitMap)
  89. {
  90.     PLANEPTR plane;
  91.     LONG pageSize;
  92.     LONG i;
  93.  
  94.     memset(bitMap,0,sizeof(*bitMap));
  95.  
  96.     bitMap->BytesPerRow    = RASSIZE(image->Width,1);
  97.     bitMap->Rows        = image->Height;
  98.     bitMap->Depth        = image->Depth;
  99.  
  100.     pageSize = RASSIZE(image->Width,image->Height);
  101.     plane = (PLANEPTR)image->ImageData;
  102.  
  103.     for(i = 0 ; i < image->Depth ; i++)
  104.     {
  105.         bitMap->Planes[i] = plane;
  106.  
  107.         plane += pageSize;
  108.     }
  109. }
  110.  
  111. /****************************************************************************/
  112.  
  113. int
  114. main(int argc,char **argv)
  115. {
  116.     struct RDArgs * rda = NULL;
  117.     struct AnchorPath * ap;
  118.     STRPTR buffer = NULL;
  119.     int result = RETURN_FAIL;
  120.     STRPTR * names = NULL;
  121.     BOOL matched = FALSE;
  122.     LONG error = OK;
  123.     STRPTR str;
  124.  
  125.     if(IconBase->lib_Version < 44)
  126.     {
  127.         Printf("Could not open icon.library V44\n");
  128.         goto out;
  129.     }
  130.  
  131.     rda = ReadArgs("FILES/A/M",(LONG *)&names,NULL);
  132.     if(rda == NULL)
  133.     {
  134.         error = IoErr();
  135.         goto out;
  136.     }
  137.  
  138.     ap = AllocVec(sizeof(*ap) + MAX_PATH_LEN,MEMF_ANY);
  139.     if(ap == NULL)
  140.     {
  141.         error = ERROR_NO_FREE_STORE;
  142.         goto out;
  143.     }
  144.  
  145.     buffer = AllocVec(MAX_PATH_LEN,MEMF_ANY);
  146.     if(buffer == NULL)
  147.     {
  148.         error = ERROR_NO_FREE_STORE;
  149.         goto out;
  150.     }
  151.  
  152.     while((error == OK) && (str = (*names++)) != NULL)
  153.     {
  154.         memset(ap,0,sizeof(*ap));
  155.  
  156.         ap->ap_BreakBits = SIGBREAKF_CTRL_C;    
  157.         ap->ap_Strlen = MAX_PATH_LEN;
  158.  
  159.         matched = TRUE;
  160.  
  161.         error = MatchFirst(str,ap);
  162.         if(error == OK)
  163.         {
  164.             if(FIB_IS_DRAWER(&ap->ap_Info))
  165.             {
  166.                 ap->ap_Flags |= APF_DODIR;
  167.  
  168.                 error = MatchNext(ap);
  169.                 ap->ap_Flags &= ~APF_DIDDIR;
  170.             }
  171.  
  172.             while(error == OK)
  173.             {
  174.                 int len;
  175.  
  176.                 strcpy(buffer,ap->ap_Buf);
  177.                 len = strlen(buffer);
  178.  
  179.                 error = MatchNext(ap);
  180.  
  181.                 if(len < strlen(".info") || Stricmp(&buffer[len - strlen(".info")],".info") != SAME)
  182.                 {
  183.                     struct DiskObject * icon;
  184.                     LONG why;
  185.  
  186.                     Printf("Getting icon for \"%s\"... ",buffer);
  187.                     Flush(Output());
  188.  
  189.                     icon = GetIconTags(buffer,
  190.                         ICONA_ErrorCode,&why,
  191.                     TAG_DONE);
  192.  
  193.                     if(icon != NULL)
  194.                     {
  195.                         LONG isPaletteMapped;
  196.  
  197.                         IconControl(icon,
  198.                             ICONCTRLA_IsPaletteMapped,&isPaletteMapped,
  199.                         TAG_DONE);
  200.  
  201.                         if(isPaletteMapped)
  202.                         {
  203.                             IconControl(icon,
  204.                                 ICONCTRLA_SetFrameless,TRUE,
  205.                             TAG_DONE);
  206.  
  207.                             Printf("writing it back... ");
  208.                             Flush(Output());
  209.     
  210.                             if(PutIconTags(buffer,icon,
  211.                                 ICONPUTA_DropNewIconToolTypes,TRUE,
  212.                                 ICONPUTA_NotifyWorkbench,TRUE,
  213.                                 ICONA_ErrorCode,&why,
  214.                             TAG_DONE))
  215.                             {
  216.                                 Printf("ok.\n");
  217.                             }
  218.                         }
  219.                         else
  220.                         {
  221.                             Printf("not a palette mapped icon.\n");
  222.                         }
  223.  
  224.                         FreeDiskObject(icon);
  225.                     }
  226.  
  227.                     if(why != OK)
  228.                     {
  229.                         UBYTE errorString[100];
  230.                         int len;
  231.  
  232.                         Fault(why,NULL,errorString,sizeof(errorString));
  233.  
  234.                         len = strlen(errorString);
  235.                         while(len > 0 && errorString[len-1] == '\n')
  236.                             errorString[--len] = '\0';
  237.  
  238.                         Printf("failed (%s).\n",errorString);
  239.                     }
  240.                 }
  241.             }
  242.         }
  243.  
  244.         if(error == ERROR_NO_MORE_ENTRIES)
  245.             error = OK;
  246.  
  247.         MatchEnd(ap);
  248.         matched = FALSE;
  249.     }
  250.  
  251.     if(error == OK)
  252.         result = RETURN_OK;
  253.     else if (error == ERROR_BREAK)
  254.         result = RETURN_WARN;
  255.     else
  256.         result = RETURN_ERROR;
  257.  
  258.  out:
  259.  
  260.     if(matched)
  261.         MatchEnd(ap);
  262.  
  263.     FreeVec(ap);
  264.     FreeVec(buffer);
  265.     FreeArgs(rda);
  266.  
  267.     if(error != OK)
  268.         PrintFault(error,FilePart(argv[0]));
  269.  
  270.     return(result);
  271. }
  272.