#include "aib.h"
#include "extern.h"


/* prototypes */
void other_gads (struct Gadget *,UWORD);
void replace_flags (void);
void capture_flags (void);
void Modify_Theirs (void);
void capture_params(void);
void replace_params(void);


/************************* modified ***************************************/

void Modify_Theirs (void)
{
WORD zoom[4];

zoom[0]=theirs.zl;
zoom[1]=theirs.zt;
zoom[2]=theirs.zw;
zoom[3]=theirs.zh;

if (theirs.sketchpad) CloseWindow(theirs.sketchpad);
if (their_menu) 
{
	if (menu) FreeMenus(menu);
	if ( !(menu=CreateMenus(their_menu,GTMN_FrontPen,0,
		TAG_DONE))) abort_me("no menu!");
	if (!(LayoutMenus(menu,vi,
		GTMN_TextAttr,menuta,
		TAG_DONE))) abort_me("no layout!");
}

if (theirs.zoom)
theirs.sketchpad = OpenWindowTags(NULL,
           WA_Activate, theirs.act,
           WA_IDCMP,CLOSEWINDOW | NEWSIZE | REFRESHWINDOW | MENUPICK |
                    SLIDERIDCMP | STRINGIDCMP | BUTTONIDCMP |
                    CHECKBOXIDCMP | MXIDCMP | MENUPICK |LISTVIEWIDCMP,
	   WA_Gadgets,sketchlist,
	   WA_Left,theirs.left,
	   WA_Width,theirs.width,
	   WA_Top,theirs.top,
	   WA_Height,theirs.height,
           WA_InnerHeight,theirs.innerh,
	   WA_InnerWidth,theirs.innerw,
           WA_DragBar,theirs.drag,
           WA_DepthGadget, theirs.depth,
           WA_CloseGadget, theirs.close,
	   WA_SizeGadget, theirs.size,
	   WA_MinWidth,theirs.minw,
	   WA_MinHeight,theirs.minh,
	   WA_MaxHeight,theirs.maxh,
	   WA_MaxWidth,theirs.maxw,
	   WA_RptQueue,theirs.rpt,
	   WA_Backdrop, theirs.back,
	   WA_ReportMouse,theirs.report,
	   WA_NoCareRefresh, theirs.nocare,
	   WA_Borderless, theirs.bord,
	   WA_SimpleRefresh,TRUE,
	   WA_RMBTrap, theirs.rmb,
           WA_Title,theirs.title,
	   WA_Zoom,zoom, 
           TAG_DONE);

else 
   theirs.sketchpad  =   OpenWindowTags(NULL,
           WA_Activate, theirs.act,
           WA_IDCMP,CLOSEWINDOW | NEWSIZE | REFRESHWINDOW | MENUPICK |
                    SLIDERIDCMP | STRINGIDCMP | BUTTONIDCMP |
                    CHECKBOXIDCMP | MXIDCMP | MENUPICK |LISTVIEWIDCMP,
	   WA_Gadgets,sketchlist,
	   WA_Left,theirs.left,
	   WA_Width,theirs.width, 
	   WA_Top,theirs.top,
	   WA_Height,theirs.height,
           WA_InnerHeight,theirs.innerh,
	   WA_InnerWidth,theirs.innerw,
           WA_DragBar,theirs.drag,
           WA_DepthGadget, theirs.depth,
           WA_CloseGadget, theirs.close,
	   WA_SizeGadget, theirs.size,
	   WA_MinWidth,theirs.minw,
	   WA_MinHeight,theirs.minh,
	   WA_MaxHeight,theirs.maxh,
	   WA_MaxWidth,theirs.maxw,
	   WA_RptQueue,theirs.rpt,
	   WA_Backdrop, theirs.back,
	   WA_ReportMouse,theirs.report,
	   WA_NoCareRefresh, theirs.nocare,
	   WA_Borderless, theirs.bord,
	   WA_RMBTrap, theirs.rmb,
           WA_Title,theirs.title,
	   WA_SimpleRefresh,TRUE,
           TAG_DONE);


	GT_RefreshWindow(theirs.sketchpad,NULL); 
	if (their_menu) SetMenuStrip(theirs.sketchpad,menu);
}



/****************** other gads (for windows )*********************************/
void other_gads (struct Gadget *gad, UWORD code)
{


switch (gad->GadgetID) {
	
	/* toggle window flags */

	case W1_size:	
		their.size = (their.size)?FALSE:TRUE;
		printf("%d\n",their.size);
		break;

	case W1_drag:
		their.drag = (their.drag)?FALSE:TRUE;
		break;

	case W1_dept:
		their.depth = (their.depth)?FALSE:TRUE;
		break;

	case W1_clos:
		their.close = (their.close)?FALSE:TRUE;
		break;

	case W1_back:
		their.back = (their.back)?FALSE:TRUE;
		break;

	case W1_repo:
		their.report = (their.report)?FALSE:TRUE;
		break;

	case W1_noca:
		their.nocare = (their.nocare)?FALSE:TRUE;
		break;

	case W1_bord:
		their.bord = (their.bord)?FALSE:TRUE;
		break;

	case W1_acti:
		their.act = (their.act)?FALSE:TRUE;
		break;

	case W1_rmbt:
		their.rmb = (their.rmb)?FALSE:TRUE;
		break;

	case W1_simp:
		their.simple = (their.simple)?FALSE:TRUE;
		break;

	case W1_smar:
		their.smart = (their.smart)?FALSE:TRUE;
		break;

	case W1_sizer:
		their.sizer = (their.sizer)?FALSE:TRUE;
		break;

	case W1_sizeb:
		their.sizeb = (their.sizeb)?FALSE:TRUE;
		break;

	case W1_auto:
		their.aut = (their.aut)?FALSE:TRUE;
		break;

	case W1_gimm:
		their.gimme = (their.gimme)?FALSE:TRUE;
		break;

	/*** main window specs ****/


	case W_tit:
		strcpy(their.title,((struct StringInfo *)gad->SpecialInfo)->Buffer);
		break;

	case W_lef:
		their.left = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
	        break;

	case W_top:
		their.top = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
	        break;

	case W_wid:
		their.width = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
	        break;

	case W_hei:
		their.height = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
	        break;

	case W_IDC:
	        break;

	case W_fla:
	        break;

	case W_minw:
		their.minw = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
	        break;

	case W_minh:
		their.minh = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
	        break;

	case W_maxw:
		their.maxw = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
	        break;

	case W_maxh:
		their.maxh = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
	        break;

	case W_inw:
		their.innerw = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
	        break;

	case W_inh:
		their.innerh = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
	        break;

	case W_pubn:
	        break;

	case W_pub:
	        break;

	case W_pubf:
	        break;

	case W_zoo1:
		their.zl = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
	        break;

	case W_zoo2:
		their.zt = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
	        break;

	case W_zoo3:
		their.zw = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
	        break;

	case W_zoo4:
		their.zh = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
	        break;

	case W_zoo:

		their.zoom = (their.zoom)?FALSE:TRUE;
	
		GT_SetGadgetAttrs(zt,window,NULL,
		GA_Disabled,!their.zoom,
		TAG_DONE);

		GT_SetGadgetAttrs(zw,window,NULL,
		GA_Disabled,!their.zoom,
		TAG_DONE);

		GT_SetGadgetAttrs(zh,window,NULL,
		GA_Disabled,!their.zoom,
		TAG_DONE);

		GT_SetGadgetAttrs(zl,window,NULL,
		GA_Disabled,!their.zoom,
		TAG_DONE);
	        break;

	case W_rpt:
		their.report = ((struct StringInfo *)gad->SpecialInfo)->LongInt;
	        break;
	
	default:
		menu_opts(gad, code);	
		break;

  }
}


/******************************* capture params ****************************/

void capture_params(void)
{

 their.top = theirs.top;
 their.width = theirs.width;
 strcpy (their.title,theirs.title);
 their.height = theirs.height;
 their.left = theirs.left;
 their.minw = theirs.minw;
 their.minh = theirs.minh;
 their.maxh = theirs.maxh;
 their.maxw = theirs.maxw;
 their.innerw = theirs.innerw;
 their.innerh = theirs.innerh;
 their.rpt = theirs.rpt;
 their.zt = theirs.zt;
 their.zh = theirs.zh;
 their.zl = theirs.zl;
 their.zw = theirs.zw;
 their.zoom = theirs.zoom;
 their.flags = theirs.flags;

}

/************************* replace params ********************************/
void replace_params(void)
{

 theirs.top = their.top;
 theirs.width = their.width;
 strcpy (theirs.title,their.title);
 theirs.height = their.height;
 theirs.left = their.left;
 theirs.minw = their.minw;
 theirs.minh = their.minh;
 theirs.maxh = their.maxh;
 theirs.maxw = their.maxw;
 theirs.innerw = their.innerw;
 theirs.innerh = their.innerh;
 theirs.rpt = their.rpt;
 theirs.zt = their.zt;
 theirs.zh = their.zh;
 theirs.zl = their.zl;
 theirs.zw = their.zw;
 theirs.zoom = their.zoom;
 theirs.flags = their.flags;

 Modify_Theirs();

}


/******************* replace flags ******************************************/

void replace_flags(void)
{

  theirs.size = their.size;
  theirs.drag = their.drag;
  theirs.depth = their.depth;
  theirs.close = their.close;
  theirs.back = their.back;
  theirs.report = their.report;
  theirs.nocare = their.nocare;
  theirs.bord = their.bord;
  theirs.act = their.act;
  theirs.rmb = their.rmb;
  theirs.simple = their.simple;
  theirs.smart = their.smart;
  theirs.sizer = their.sizer;
  theirs.sizeb = their.sizeb;
  theirs.aut = their.aut;
  theirs.gimme = their.gimme;

  Modify_Theirs();
 

}


/*********************** caputre flags **********************************/

void capture_flags(void)
{
  their.size = theirs.size;
  their.drag = theirs.drag;
  their.depth = theirs.depth;
  their.close = theirs.close;
  their.back = theirs.back;
  their.report = theirs.report;
  their.nocare = theirs.nocare;
  their.bord = theirs.bord;
  their.act = theirs.act;
  their.rmb = theirs.rmb;
  their.simple = theirs.simple;
  their.smart = theirs.smart;
  their.sizer = theirs.sizer;
  their.sizeb = theirs.sizeb;
  their.aut = theirs.aut;
  their.gimme = theirs.gimme;
 
}

