home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_3.5 / Examples / Icon / LayoutIcon.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-30  |  5.3 KB  |  248 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 <intuition/intuition.h>
  22.  
  23. #include <graphics/modeid.h>
  24.  
  25. #include <dos/dosextens.h>
  26. #include <dos/dosasl.h>
  27. #include <dos/rdargs.h>
  28.  
  29. #include <exec/memory.h>
  30.  
  31. #include <workbench/workbench.h>
  32.  
  33. #include <clib/exec_protos.h>
  34. #include <clib/intuition_protos.h>
  35. #include <clib/graphics_protos.h>
  36. #include <clib/utility_protos.h>
  37. #include <clib/layers_protos.h>
  38. #include <clib/dos_protos.h>
  39.  
  40. #include <pragmas/exec_sysbase_pragmas.h>
  41. #include <pragmas/intuition_pragmas.h>
  42. #include <pragmas/graphics_pragmas.h>
  43. #include <pragmas/utility_pragmas.h>
  44. #include <pragmas/layers_pragmas.h>
  45. #include <pragmas/dos_pragmas.h>
  46.  
  47. #include <string.h>
  48.  
  49. /****************************************************************************/
  50.  
  51. extern struct Library * IntuitionBase;
  52. extern struct Library * GfxBase;
  53. extern struct Library * SysBase;
  54. extern struct Library * DOSBase;
  55. extern struct Library * UtilityBase;
  56. extern struct Library * IconBase;
  57. extern struct Library * LayersBase;
  58.  
  59. /****************************************************************************/
  60.  
  61. #include <workbench/icon.h>
  62. #include <clib/icon_protos.h>
  63. #include <pragmas/icon_pragmas.h>
  64.  
  65. /****************************************************************************/
  66.  
  67. #define OK (0)
  68. #define SAME (0)
  69.  
  70. /****************************************************************************/
  71.  
  72. #define MAX_PATH_LEN 1024
  73.  
  74. /****************************************************************************/
  75.  
  76. #define FIB_IS_DRAWER(fib)    ((fib)->fib_DirEntryType > 0)
  77. #define FIB_IS_FILE(fib)    ((fib)->fib_DirEntryType < 0)
  78.  
  79. /****************************************************************************/
  80.  
  81. int
  82. main(int argc,char **argv)
  83. {
  84.     static ULONG states[] =
  85.     {
  86.         IDS_NORMAL,
  87.         IDS_SELECTED,
  88.         IDS_DISABLED,
  89.         IDS_SELECTEDDISABLED
  90.     };
  91.     int numStates = sizeof(states) / sizeof(states[0]);
  92.     int state = 0;
  93.     struct RDArgs * rda = NULL;
  94.     int result = RETURN_FAIL;
  95.     LONG error = OK;
  96.     STRPTR name = NULL;
  97.     struct Screen * screen = NULL;
  98.     struct Window * window = NULL;
  99.     struct DiskObject * icon = NULL;
  100.     UWORD pens[] = { (UWORD)~0 };
  101.     struct IntuiMessage * imsg;
  102.     BOOL relayout;
  103.     BOOL done;
  104.  
  105.     if(IconBase->lib_Version < 44)
  106.     {
  107.         Printf("Could not open icon.library V44\n");
  108.         goto out;
  109.     }
  110.  
  111.     rda = ReadArgs("FILE/A",(LONG *)&name,NULL);
  112.     if(rda == NULL)
  113.     {
  114.         error = IoErr();
  115.         goto out;
  116.     }
  117.  
  118.     icon = GetIconTags(name,
  119.         ICONGETA_RemapIcon,FALSE,
  120.         ICONA_ErrorCode,&error,
  121.     TAG_DONE);
  122.     if(icon == NULL)
  123.         goto out;
  124.  
  125.     screen = OpenScreenTags(NULL,
  126.         SA_DisplayID,    DEFAULT_MONITOR_ID | HIRESLACE_KEY,
  127.         SA_Depth,        4,
  128.         SA_Title,        "icon layout test",
  129.         SA_SysFont,        1,
  130.         SA_Pens,        pens,
  131.         SA_SharePens,    TRUE,
  132.         SA_Interleaved,    TRUE,
  133.     TAG_DONE);
  134.     if(screen == NULL)
  135.     {
  136.         error = ERROR_NO_FREE_STORE;
  137.         goto out;
  138.     }
  139.  
  140.     window = OpenWindowTags(NULL,
  141.         WA_CustomScreen,    screen,
  142.         WA_Activate,        TRUE,
  143.         WA_DepthGadget,        TRUE,
  144.         WA_DragBar,            TRUE,
  145.         WA_CloseGadget,        TRUE,
  146.         WA_SizeGadget,        TRUE,
  147.         WA_InnerWidth,        10 + icon->do_Gadget.Width,
  148.         WA_InnerHeight,        10 + icon->do_Gadget.Height,
  149.         WA_IDCMP,            IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE | IDCMP_VANILLAKEY,
  150.         WA_MaxWidth,        screen->Width,
  151.         WA_MaxHeight,        screen->Height,
  152.     TAG_DONE);
  153.     if(window == NULL)
  154.     {
  155.         error = ERROR_NO_FREE_STORE;
  156.         goto out;
  157.     }
  158.  
  159.     WindowLimits(window,
  160.         window->BorderLeft + 10 + window->BorderRight,
  161.         window->BorderTop + 10 + window->BorderBottom,
  162.         0,0);
  163.  
  164.     relayout = TRUE;
  165.     done = FALSE;
  166.  
  167.     do
  168.     {
  169.         if(relayout)
  170.         {
  171. /*            if(LayoutIcon(icon,screen,OBP_Precision,PRECISION_EXACT,TAG_DONE))*/
  172.             if(LayoutIconA(icon,NULL,NULL))
  173.             {
  174.                 struct Region * newRegion;
  175.  
  176.                 newRegion = NewRegion();
  177.                 if(newRegion != NULL)
  178.                 {
  179.                     struct Rectangle rect;
  180.                     
  181.                     LockLayerRom(window->WLayer);
  182.  
  183.                     rect.MinX = window->BorderLeft;
  184.                     rect.MinY = window->BorderTop;
  185.                     rect.MaxX = window->Width - (window->BorderRight + 1);
  186.                     rect.MaxY = window->Height - (window->BorderBottom + 1);
  187.  
  188.                     if(OrRectRegion(newRegion,&rect))
  189.                     {
  190.                         struct Region * oldRegion;
  191.  
  192.                         oldRegion = InstallClipRegion(window->WLayer,newRegion);
  193.                         DrawIconStateA(window->RPort,icon,NULL,window->BorderLeft,window->BorderTop,states[state],NULL);
  194.                         InstallClipRegion(window->WLayer,oldRegion);
  195.                     }
  196.  
  197.                     UnlockLayerRom(window->WLayer);
  198.  
  199.                     DisposeRegion(newRegion);
  200.                 }
  201.             }
  202.  
  203.             relayout = FALSE;
  204.         }
  205.  
  206.         WaitPort(window->UserPort);
  207.  
  208.         while((imsg = (struct IntuiMessage *)GetMsg(window->UserPort)) != NULL)
  209.         {
  210.             if(imsg->Class == IDCMP_CLOSEWINDOW)
  211.                 done = TRUE;
  212.  
  213.             if(imsg->Class == IDCMP_NEWSIZE)
  214.                 relayout = TRUE;
  215.  
  216.             if(imsg->Class == IDCMP_VANILLAKEY)
  217.             {
  218.                 state = (state + 1) % numStates;
  219.  
  220.                 relayout = TRUE;
  221.             }
  222.  
  223.             ReplyMsg((struct Message *)imsg);
  224.         }
  225.     }
  226.     while(NOT done);
  227.  
  228.     result = RETURN_OK;
  229.  
  230.  out:
  231.  
  232.     if(icon != NULL)
  233.         FreeDiskObject(icon);
  234.  
  235.     if(window != NULL)
  236.         CloseWindow(window);
  237.  
  238.     if(screen != NULL)
  239.         CloseScreen(screen);
  240.  
  241.     FreeArgs(rda);
  242.  
  243.     if(error != OK)
  244.         PrintFault(error,FilePart(argv[0]));
  245.  
  246.     return(result);
  247. }
  248.