/******************************************************************************************************

					Icon2Gadget.c

	This file reads an icon from the disk and places it in a Window, where it will be set up
	as a Gadget. This can now be clicked from Steal to get a Gadget's representation of the
	icon. Unfortunately, this cannot be done from the WorkBench, as WorkBench does not make
	it's icons hang from IntuitionBase.

							Rick van Rein, Februari 7, 1991

******************************************************************************************************/



#include <functions.h>
#include <intuition/intuition.h>
#include <workbench/workbench.h>


struct NewWindow nwin =
 {
   0, 0, 0, 0,
   -1, -1,
   CLOSEWINDOW,
   SMART_REFRESH | WINDOWDEPTH | WINDOWCLOSE | WINDOWDRAG,
   NULL,
   NULL,
   (UBYTE *) "Icon2Gadget",
   NULL,
   NULL,
   -1, -1, -1, -1,
   WBENCHSCREEN
 };

extern void *IconBase;

void *IntuitionBase;


main (argc,argv)
   int argc;
   char *argv [];
 {
   struct DiskObject *dob;
   struct Window *win;

   if (argc != 2)
      puts ("\tIcon2Gadget: Please 1 argument: An iconfile without \".info\"");
   else
    {
      IntuitionBase = OpenLibrary ("intuition.library", 0L);	/* This call will succeed always */
      if (!(IconBase = OpenLibrary ("icon.library", 0L)))
         puts ("\tIcon2Gadget: Can't open icon.library");
      else
       {
         if (dob = GetDiskObject (argv [1]))
	  {
	    nwin.FirstGadget = &dob->do_Gadget;
	    nwin.Width = 10 + dob->do_Gadget.Width;
	    if (nwin.Width < 100)
	       nwin.Width = 100;
	    nwin.Height = 20 + dob->do_Gadget.Height;
	    dob->do_Gadget.LeftEdge = 5;
	    dob->do_Gadget.TopEdge = 15;
	    dob->do_Gadget.NextGadget = NULL;
	    if (win = OpenWindow (&nwin))
	     {
	       WaitPort (win->UserPort);		/* Wait for CLOSEWINDOW message over IDCMP */
	       ReplyMsg (GetMsg (win->UserPort));
	       CloseWindow (win);
	     }
	    else
	       puts ("\tIcon2Gadget: Can't open Window for Gadget");
	    FreeDiskObject (dob);
	  }
	 else
	    puts ("\tIcon2Gadget: Can't find the given iconfile");
         CloseLibrary (IconBase);
       }
      CloseLibrary (IntuitionBase);
    }
 }
