


                             'ShowGadgets 1.0'
                             [33m----------------[0m
                             by PowerPeak '90

    This utility shows all gadgets in the active window. When you press
AMIGA-AMIGA-G the active window will be cleared and all gadgets are shown
as rectangles. The window will be restored when you press the left
mouse-button. Very useful for debugging your programs and checking for
hidden gadgets in other programs (preferences 1.2 :-) .
    This month again a C program. Compile with Lattice C 5.04 or it will
not work !



[42m~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[42m                                 ShowGadgets.c                               
[42m-----------------------------------------------------------------------------

/*========================================================*/
/*							  */
/* Show gadgets in a window V1.0			  */
/* © J.Tyberghein					  */
/*    Mon Mar  5 09:16:17 1990 V1.0			  */
/*							  */
/*========================================================*/

#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <exec/interrupts.h>
#include <devices/inputevent.h>
#include <devices/input.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <string.h>

/*=============================== Data =====================================*/

APTR SysBase;
struct DosLibrary *DOSBase;
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;

void OpenStuff ();
void __regargs CloseStuff (int);
void Print (char *);


[42m-----------------------------------------------------------------------------
[42m  NewWindow structure for our dummy window                                   
[42m-----------------------------------------------------------------------------
[0m                                                                             
struct NewWindow nWin =
  {
    0,0,0,0,0,1,
    NULL,
    BORDERLESS,
    NULL,NULL,NULL,NULL,NULL,
    0,0,0,0,
    CUSTOMSCREEN
  };


[42m-----------------------------------------------------------------------------
[42m  Press AMIGA-AMIGA-G for view gadgets, and AMIGA-AMIGA-ESC to quit          
[42m-----------------------------------------------------------------------------
[0m                                                                             
#define GKEY	    0x24
#define ESCAPEKEY   0x45


[42m-----------------------------------------------------------------------------
[42m  The following structure is needed to pass information from our input       
[42m  device handler to our task and vice versa                                  
[42m-----------------------------------------------------------------------------
[0m                                                                             
typedef struct
  {
    struct Task *TaskToSig;	  /* Pointer to our own task */
    ULONG QuitSig,QuitSigNum;	  /* Signal to quit ShowGadgets */
    ULONG ActionSig,ActionSigNum; /* Someone pressed AMIGA-AMIGA-G */
  } Global_Data;

Global_Data Global;


[42m-----------------------------------------------------------------------------
[42m  Our port and requestblock for the input device                             
[42m-----------------------------------------------------------------------------
[0m                                                                             
struct MsgPort *InputDevPort = NULL;
struct IOStdReq *InputRequestBlock = NULL;
struct Interrupt HandlerStuff;

/*=============================== Code =====================================*/


/*------------------------------ main program ------------------------------*/

void __saveds myMain ()
{
  struct Window *win,*myWin;
  int w,h,sig,xx,yy;
  struct RastPort *rp;
  struct Gadget *g;

  OpenStuff ();
  Print ("[01mShowGadgets 1.0[00m  [33mWritten by J.Tyberghein 5 Mar 90[31m\n");
  Print ("Press 'AMIGA-AMIGA-G' for gadget view ");
  Print ("(Left mouse button to stop view)\n");
  Print ("Press 'AMIGA-AMIGA-ESC' to quit\n");

[42m-----------------------------------------------------------------------------
[42m  Wait for signals from our input device                                     
[42m-----------------------------------------------------------------------------
[0m                                                                             
  for ( ; ; )
    {
      sig = Wait (Global.QuitSig | Global.ActionSig);
      if (sig & Global.QuitSig) break;
      if (sig & Global.ActionSig)

[42m-----------------------------------------------------------------------------
[42m  Now we show all gadgets for the active window                              
[42m-----------------------------------------------------------------------------
[0m                                                                             
	{
	  win = IntuitionBase->ActiveWindow;
	  nWin.LeftEdge = win->LeftEdge;
	  nWin.TopEdge = win->TopEdge;
	  w = nWin.Width = win->Width;
	  h = nWin.Height = win->Height;
	  nWin.Screen = win->WScreen;

[42m-----------------------------------------------------------------------------
[42m  Open our new window on top of the other window                             
[42m-----------------------------------------------------------------------------
[0m                                                                             
	  if (!(myWin = (struct Window *)OpenWindow (&nWin)))
	    {
	      Print ("Error opening window\n");
	      DisplayBeep (0L);
	    }
	  else
	    {
	      rp = myWin->RPort;

[42m-----------------------------------------------------------------------------
[42m  Forbid multitasking to prevent the other task from messing with its        
[42m  gadgets                                                                    
[42m-----------------------------------------------------------------------------
[0m                                                                             
	      Forbid ();
	      SetRast (rp,0L);
	      SetAPen (rp,1L);

[42m-----------------------------------------------------------------------------
[42m  Scan all gadgets                                                           
[42m-----------------------------------------------------------------------------
[0m                                                                             
	      g = win->FirstGadget;
	      while (g)
		{
		  int x1,y1,x2,y2;


[42m-----------------------------------------------------------------------------
[42m  Compute the location for this gadget                                       
[42m-----------------------------------------------------------------------------
[0m                                                                             
		  x1 = g->LeftEdge; y1 = g->TopEdge;
		  if (g->Flags & GRELRIGHT) x1 += w;
		  if (g->Flags & GRELBOTTOM) y1 += h;
		  if (g->Flags & GRELWIDTH) xx = x2 = x1+g->Width+w-1;
		  else x2 = x1+g->Width-1;
		  if (g->Flags & GRELHEIGHT) yy = y2 = y1+g->Height+h-1;
		  else y2 = y1+g->Height-1;

[42m-----------------------------------------------------------------------------
[42m  Draw a box on our window representing the gadget on the other window       
[42m-----------------------------------------------------------------------------
[0m                                                                             
		  Move (rp,x1,y1);
		  Draw (rp,x2,y1);
		  Draw (rp,x2,y2);
		  Draw (rp,x1,y2);
		  Draw (rp,x1,y1);
		  g = g->NextGadget;
		}

[42m-----------------------------------------------------------------------------
[42m  Wait for the leftmousebutton                                               
[42m-----------------------------------------------------------------------------
[0m                                                                             
	      while ((*(BYTE *)0xbfe001)&64) ;
	      CloseWindow (myWin);
	      Permit ();
	    }
	}
    }
  Print ("Done !\n");
  CloseStuff (0);
}

/*-------------------------- Print something -------------------------------*/

void Print (char *str)
{
  Write (Output (),str,strlen (str));
}

/*------------------------ InputEvent handler ------------------------------*/

struct InputEvent * __saveds __asm MyHandler
      (register __a0 struct InputEvent *ev, register __a1 Global_Data *gdptr)
{
  register struct InputEvent *ep;


[42m-----------------------------------------------------------------------------
[42m  For each event...                                                          
[42m-----------------------------------------------------------------------------
[0m                                                                             
  for (ep=ev ; ep ; ep=ep->ie_NextEvent)
    if (ep->ie_Class == IECLASS_RAWKEY)
      if (ep->ie_Code == GKEY && (ep->ie_Qualifier &
	IEQUALIFIER_RCOMMAND) && (ep->ie_Qualifier & IEQUALIFIER_LCOMMAND))

[42m-----------------------------------------------------------------------------
[42m  The user pressed AMIGA-AMIGA-G, send a signal to the main task             
[42m-----------------------------------------------------------------------------
[0m                                                                             
	{
	  ep->ie_Class = IECLASS_NULL;
	  Signal (gdptr->TaskToSig,gdptr->ActionSig);
	}
      else if (ep->ie_Code == ESCAPEKEY && (ep->ie_Qualifier &
	IEQUALIFIER_RCOMMAND) && (ep->ie_Qualifier & IEQUALIFIER_LCOMMAND))

[42m-----------------------------------------------------------------------------
[42m  Tell the main task to quit                                                 
[42m-----------------------------------------------------------------------------
[0m                                                                             
	{
	  ep->ie_Class = IECLASS_NULL;
	  Signal (gdptr->TaskToSig,gdptr->QuitSig);
	}
  return (ev);
}

/*----------------------------- OpenStuff ----------------------------------*/

void OpenStuff ()
{

[42m-----------------------------------------------------------------------------
[42m  We must use SysBase because we don't use the standard startup code         
[42m-----------------------------------------------------------------------------
[0m                                                                             
  SysBase = (APTR)*(LONG *)4;

[42m-----------------------------------------------------------------------------
[42m  Open all libraries                                                         
[42m-----------------------------------------------------------------------------
[0m                                                                             
  DOSBase = (struct DosLibrary *)OpenLibrary ("dos.library",0L);
  IntuitionBase = (struct IntuitionBase *)
    OpenLibrary ("intuition.library",0L);
  GfxBase = (struct GfxBase *)OpenLibrary ("graphics.library",0L);

[42m-----------------------------------------------------------------------------
[42m  Allocate our signals                                                       
[42m-----------------------------------------------------------------------------
[0m                                                                             
  Global.QuitSigNum = Global.ActionSigNum = 0L;
  Global.TaskToSig = FindTask (0L);
  if ((Global.QuitSigNum = AllocSignal (-1L)) == -1L)
    {
      Print ("Error allocating signal\n");
      CloseStuff (4);
    }
  Global.QuitSig = 1L<<Global.QuitSigNum;
  if ((Global.ActionSigNum = AllocSignal (-1L)) == -1L)
    {
      Print ("Error allocating signal\n");
      CloseStuff (4);
    }
  Global.ActionSig = 1L<<Global.ActionSigNum;

[42m-----------------------------------------------------------------------------
[42m  Create the port and the StdIO for our input device                         
[42m-----------------------------------------------------------------------------
[0m                                                                             
  if (!(InputDevPort = CreatePort (0L,0L)))
    {
      Print ("Error creating InputDevPort\n");
      CloseStuff (1);
    }
  if (!(InputRequestBlock = CreateStdIO (InputDevPort)))
    {
      Print ("Error creating Standard IO\n");
      CloseStuff (2);
    }

[42m-----------------------------------------------------------------------------
[42m  Initialize the interrupt structure                                         
[42m  We set our priority to 53. This is higher than the priority for the        
[42m  intuition input device (50) so we are called before intuition              
[42m-----------------------------------------------------------------------------
[0m                                                                             
  HandlerStuff.is_Data = (APTR)&Global;
  HandlerStuff.is_Code = (VOID (*)())MyHandler;
  HandlerStuff.is_Node.ln_Pri = 53;
  if (OpenDevice ("input.device",0L,(struct IORequest *)InputRequestBlock,0L))
    {
      Print ("Error opening Input.device\n");
      CloseStuff (3);
    }

[42m-----------------------------------------------------------------------------
[42m  Add our handler                                                            
[42m-----------------------------------------------------------------------------
[0m                                                                             
  InputRequestBlock->io_Command = IND_ADDHANDLER;
  InputRequestBlock->io_Data = (APTR)&HandlerStuff;
  DoIO ((struct IORequest *)InputRequestBlock);
}

/*---------------------------- CloseStuff ----------------------------------*/

void __regargs CloseStuff (int Error)
{
  if (DOSBase) CloseLibrary ((struct Library *)DOSBase);
  if (IntuitionBase) CloseLibrary ((struct Library *)IntuitionBase);
  if (GfxBase) CloseLibrary ((struct Library *)GfxBase);
  if (Global.ActionSigNum) FreeSignal (Global.ActionSigNum);
  if (Global.QuitSigNum) FreeSignal (Global.QuitSigNum);
  if (InputRequestBlock)
    {
      InputRequestBlock->io_Command = IND_REMHANDLER;
      InputRequestBlock->io_Data = (APTR)&HandlerStuff;
      DoIO ((struct IORequest *)InputRequestBlock);
      CloseDevice ((struct IORequest *)InputRequestBlock);
      DeleteStdIO (InputRequestBlock);
    }
  if (InputDevPort) DeletePort (InputDevPort);
  Exit (Error);
}


[42m-----------------------------------------------------------------------------
[42m   The end.                                                 Jorrit Tyberghein
[42m-----------------------------------------------------------------------------
[0m                                                                             
