/*	This program demonstrates how one can create a gadget for a window
		which allows you to drag the window by clicking anywhere in the window
		that does not have a ~normal~ user or system gadget
		many a time I was unable to drag a window to another screen location
		because another window was over the drag bar and the top window
		did  not have front to back gadgets

		This works as is but be advised that if you use it in your own
		program and your program allows the user to re-size the window
		then you are going to have to remove the gadget, redefine it's size
		to conform to the windows new size, and then add it back to the window

		Enjoy!   by BIT-WIZ
	*/


#include <intuition/intuitionbase.h>

struct	IntuitionBase	*IntuitionBase=NULL;
struct	Window				*wind;

/* put a gadget up in the middle to show that it takes precedence over 
   the drag gadget
 */
struct	IntuiText	gadtext= { 1,0,JAM1,5,7,NULL,"Hello",NULL } ;

struct Gadget Gadget1 = {
  NULL,				/*	next 					*/
  20,20,			/*	left, top 		*/
  50,20,			/*	width, height	*/
  GADGHCOMP,	/*	FLAGS					*/
  RELVERIFY,	/*	Activation		*/
  BOOLGADGET,	/*	Type					*/
  NULL,				/*	Render				*/
  NULL,				/*	Select				*/
  &gadtext,		/*	text					*/
  NULL,				/*	Mutual				*/
  NULL,				/*	Special				*/
  NULL,				/*	ID						*/
  NULL				/*	user info			*/
};

/* this is the full window drag gadget - add this one in LAST for it to work
   OK
 */
struct Gadget Gadget2 = {
  NULL,						/*	next 					*/
  0,0,						/*	left, top 		*/
  150,50,					/*	width, height	*/
  GADGHNONE,			/*	FLAGS					*/
  GADGIMMEDIATE,	/*	Activation		*/
  WDRAGGING,			/*	Type					*/
  NULL,						/*	Render				*/
  NULL,						/*	Select				*/
  NULL,						/*	text					*/
  NULL,						/*	Mutual				*/
  NULL,						/*	Special				*/
  NULL,						/*	ID						*/
  NULL						/*	user info			*/
};

struct NewWindow ns = {
  100,50,	/*	left, top			*/
  150,50,	/*	width, height	*/
  0,1,		/*	pens					*/
  NULL,		/*	IDCMPFLAGS		*/
  WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|SMART_REFRESH,	/*	Flags	- to show it works */
  &Gadget1,	/*	normal gadget(s)		*/
  NULL,			/*	no checkmark image	*/
  "Sample",	/*	sample text					*/
  NULL,			/*	WBENCHSCREEN				*/
  NULL,			/*	NO bitmap						*/
  0,0,			/*	don't allow sizing	*/
  0,0,			/*	don't allow sizing	*/
  WBENCHSCREEN	/*	type						*/
};

void main()
{
	int	i,j;		/* temp counters	*/
	
	IntuitionBase=(struct	IntuitionBase *)OpenLibrary("intuition.library",0L);
	if ( IntuitionBase )	wind=(struct	Window *)OpenWindow(&ns);
	if ( wind )
		{
			AddGadget(wind,&Gadget2,-1);
			RefreshGadgets(wind->FirstGadget,wind,0);
			for ( i=0 ; i < 2500 ; i++ ) for ( j=0 ; j < 1000 ; j++);	
		}
	if ( wind ) CloseWindow(wind);
	if ( IntuitionBase ) CloseLibrary(IntuitionBase);
	exit(0);
}
