/*============================================================*/
/*============================================================*/
/*==														==*/
/*==				Main Window Routines					==*/
/*==														==*/
/*============================================================*/
/*============================================================*/


/*========================================================  Includes  */

#include "Globals.h"
#include "UnivUtilities.h"
#include "MainWindow.h"
#include "Render.h"


/*========================================================  Functions  */
/*========================================================  EraseMenuBarRect  */

void EraseMenuBarRect (void)

{
	RgnHandle		newVis;
	GrafPtr			wasPort;
	Rect			theRect;
	Point			thePoint;
	
	GetPort(&wasPort);
	SetPort((GrafPtr)mainWndo);
	GetOrigin(&thePoint);
	SetOrigin(0, 0);
	
	theRect = screenBits.bounds;
	theRect.bottom = theRect.top + wasMenuBarHeight;
	
	newVis = NewRgn();
	RectRgn(newVis, &theRect);
	
	UnionRgn(mainWndo->visRgn, newVis, mainWndo->visRgn);
	
	if (isColor)
		CopyBits(&((GrafPtr)offCWorkPtr)->portBits, &(((GrafPtr)mainWndo)->portBits), 
				&theRect, &theRect, srcCopy, kNilPointer);
	else
		CopyBits(&offWorkBits, &(mainWndo->portBits), &theRect, &theRect, 
				srcCopy, kNilPointer);
	
	DisposeRgn(newVis);
	SetOrigin(thePoint.h, thePoint.v);
	SetPort((GrafPtr)wasPort);
}


/*========================================================  FixVisRegion  */

void FixVisRegion (void)

{
	RgnHandle		newVis;
	GrafPtr			wasPort;
	Rect			theRect;
	Point			thePoint;
	
	GetPort(&wasPort);
	SetPort((GrafPtr)mainWndo);
	GetOrigin(&thePoint);
	SetOrigin(0, 0);
	
	theRect = screenBits.bounds;
	theRect.top += wasMenuBarHeight;
	
	newVis = NewRgn();
	RectRgn(newVis, &theRect);
	
	SectRgn(mainWndo->visRgn, newVis, mainWndo->visRgn);
	
	DisposeRgn(newVis);
	SetOrigin(thePoint.h, thePoint.v);
	SetPort((GrafPtr)wasPort);
}

/*========================================================  LoadBackgroundPict  */

void LoadBackgroundPict (void)

{
	Rect			pictRect;
	PicHandle		thePict;
	
	if (isColor)
	{
		SetPort((GrafPtr)offCBackPtr);
		
		if (displayMode == kDisplay13Inch)
			thePict = GetPicture(rArenaPictLg4BitID);
		else
			thePict = GetPicture(rArenaPictSm4BitID);
		
		if (thePict != kNilPointer)
		{
			HLock((Handle)thePict);
			pictRect = (**thePict).picFrame;
			DrawPicture(thePict, &pictRect);
			HUnlock((Handle)thePict);
			ReleaseResource((Handle)thePict);
		}
		else
			DeathError(kErrNoPictRsrc);
	}
	else
	{
		SetPort((GrafPtr)offBackPtr);
		
		if (displayMode == kDisplay13Inch)
			thePict = GetPicture(rArenaPictLg1BitID);
		else
			thePict = GetPicture(rArenaPictSm1BitID);
		
		if (thePict != kNilPointer)
		{
			HLock((Handle)thePict);
			pictRect = (**thePict).picFrame;
			DrawPicture(thePict, &pictRect);
			HUnlock((Handle)thePict);
			ReleaseResource((Handle)thePict);
		}
		else
			DeathError(kErrNoPictRsrc);
	}
}


/*========================================================  UpdateGoalPicts  */

void UpdateGoalPicts (Boolean drawToMain)

{
	#define 		kBackBoardHeight	20
	RGBColor		theRGBColor;
	Rect			tempRect;
	RgnHandle		leftRgn, rightRgn, tempRgn;
	GrafPtr			wasPort;
	
	LoadBackgroundPict();
	
	leftRgn = kNilPointer;
	rightRgn = kNilPointer;
	
	if (arenaSize == kSmallArena)
	{
		leftRgn = NewRgn();		/* define left & right goal regions for small arena */
		OpenRgn();
		MoveTo(6, 174);
		LineTo(14, 138);
		LineTo(39, 104);
		LineTo(78, 76);
		LineTo(132, 53);
		LineTo(191, 40);
		LineTo(256, 34);
		LineTo(256, 34 - kBackBoardHeight);
		LineTo(191, 40 - kBackBoardHeight);
		LineTo(132, 53 - kBackBoardHeight);
		LineTo(78, 76 - kBackBoardHeight);
		LineTo(39, 104 - kBackBoardHeight);
		LineTo(14, 138 - kBackBoardHeight);
		LineTo(6, 174 - kBackBoardHeight);
		LineTo(6, 174);
		CloseRgn(leftRgn);
		
		rightRgn = NewRgn();
		OpenRgn();
		MoveTo(512 - 6, 174);
		LineTo(512 - 14, 138);
		LineTo(512 - 39, 104);
		LineTo(512 - 78, 76);
		LineTo(512 - 132, 53);
		LineTo(512 - 191, 40);
		LineTo(512 - 256, 34);
		LineTo(512 - 256, 34 - kBackBoardHeight);
		LineTo(512 - 191, 40 - kBackBoardHeight);
		LineTo(512 - 132, 53 - kBackBoardHeight);
		LineTo(512 - 78, 76 - kBackBoardHeight);
		LineTo(512 - 39, 104 - kBackBoardHeight);
		LineTo(512 - 14, 138 - kBackBoardHeight);
		LineTo(512 - 6, 174 - kBackBoardHeight);
		LineTo(512 - 6, 174);
		CloseRgn(rightRgn);
	}
	else
	{
		leftRgn = NewRgn();		/* define left & right goal regions for large arena */
		OpenRgn();
		MoveTo(12, 250);
		LineTo(22, 203);
		LineTo(53, 158);
		LineTo(102, 119);
		LineTo(166, 89);
		LineTo(240, 70);
		LineTo(320, 64);
		LineTo(320, 64 - kBackBoardHeight);
		LineTo(240, 70 - kBackBoardHeight);
		LineTo(166, 89 - kBackBoardHeight);
		LineTo(102, 119 - kBackBoardHeight);
		LineTo(53, 158 - kBackBoardHeight);
		LineTo(22, 203 - kBackBoardHeight);
		LineTo(12, 250 - kBackBoardHeight);
		LineTo(12, 250);
		CloseRgn(leftRgn);
		
		rightRgn = NewRgn();
		OpenRgn();
		MoveTo(640 - 12, 250);
		LineTo(640 - 22, 203);
		LineTo(640 - 53, 158);
		LineTo(640 - 102, 119);
		LineTo(640 - 166, 89);
		LineTo(640 - 240, 70);
		LineTo(640 - 320, 64);
		LineTo(640 - 320, 64 - kBackBoardHeight);
		LineTo(640 - 240, 70 - kBackBoardHeight);
		LineTo(640 - 166, 89 - kBackBoardHeight);
		LineTo(640 - 102, 119 - kBackBoardHeight);
		LineTo(640 - 53, 158 - kBackBoardHeight);
		LineTo(640 - 22, 203 - kBackBoardHeight);
		LineTo(640 - 12, 250 - kBackBoardHeight);
		LineTo(640 - 12, 250);
		CloseRgn(rightRgn);
	}
	
	
	if (arenaSize == kSmallArena)
	{
		switch (leftGoalLeague)
		{
			case kLittleLeague:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 11, 0, 208, 384);			/* A, 0, D, 384 */
				SectRgn(leftRgn, tempRgn, leftRgn);
				SetRectRgn(tempRgn, 34, 0, 140, 384);			/* B, 0, C, 384 */
				DiffRgn(leftRgn, tempRgn, leftRgn);
				DisposeRgn(tempRgn);
				break;
			case kJuniorVarsity:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 14, 0, 188, 384);			/* A, 0, D, 384 */
				SectRgn(leftRgn, tempRgn, leftRgn);
				SetRectRgn(tempRgn, 40, 0, 132, 384);			/* B, 0, C, 384 */
				DiffRgn(leftRgn, tempRgn, leftRgn);
				DisposeRgn(tempRgn);
				break;
			case kVarsity:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 19, 0, 173, 384);			/* A, 0, D, 384 */
				SectRgn(leftRgn, tempRgn, leftRgn);
				SetRectRgn(tempRgn, 50, 0, 113, 384);			/* B, 0, C, 384 */
				DiffRgn(leftRgn, tempRgn, leftRgn);
				DisposeRgn(tempRgn);
				break;
			case kMinorLeague:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 22, 0, 166, 384);			/* A, 0, D, 384 */
				SectRgn(leftRgn, tempRgn, leftRgn);
				SetRectRgn(tempRgn, 55, 0, 104, 384);			/* B, 0, C, 384 */
				DiffRgn(leftRgn, tempRgn, leftRgn);
				DisposeRgn(tempRgn);
				break;
			case kProfessional:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 27, 0, 154, 384);			/* A, 0, D, 384 */
				SectRgn(leftRgn, tempRgn, leftRgn);
				SetRectRgn(tempRgn, 69, 0, 82, 384);			/* B, 0, C, 384 */
				DiffRgn(leftRgn, tempRgn, leftRgn);
				DisposeRgn(tempRgn);
				break;
			default:
				break;
		}
	}
	else
	{
		switch (leftGoalLeague)
		{
			case kLittleLeague:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 20, 0, 246, 480);			/* A, 0, D, 480 */
				SectRgn(leftRgn, tempRgn, leftRgn);
				SetRectRgn(tempRgn, 47, 0, 174, 480);			/* B, 0, C, 480 */
				DiffRgn(leftRgn, tempRgn, leftRgn);
				DisposeRgn(tempRgn);
				break;
			case kJuniorVarsity:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 25, 0, 230, 480);			/* A, 0, D, 480 */
				SectRgn(leftRgn, tempRgn, leftRgn);
				SetRectRgn(tempRgn, 58, 0, 158, 480);			/* B, 0, C, 480 */
				DiffRgn(leftRgn, tempRgn, leftRgn);
				DisposeRgn(tempRgn);
				break;
			case kVarsity:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 32, 0, 208, 480);			/* A, 0, D, 480 */
				SectRgn(leftRgn, tempRgn, leftRgn);
				SetRectRgn(tempRgn, 67, 0, 145, 480);			/* B, 0, C, 480 */
				DiffRgn(leftRgn, tempRgn, leftRgn);
				DisposeRgn(tempRgn);
				break;
			case kMinorLeague:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 42, 0, 190, 480);			/* A, 0, D, 480 */
				SectRgn(leftRgn, tempRgn, leftRgn);
				SetRectRgn(tempRgn, 80, 0, 125, 480);			/* B, 0, C, 480 */
				DiffRgn(leftRgn, tempRgn, leftRgn);
				DisposeRgn(tempRgn);
				break;
			case kProfessional:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 50, 0, 170, 480);			/* A, 0, D, 480 */
				SectRgn(leftRgn, tempRgn, leftRgn);
				SetRectRgn(tempRgn, 96, 0, 110, 480);			/* B, 0, C, 480 */
				DiffRgn(leftRgn, tempRgn, leftRgn);
				DisposeRgn(tempRgn);
				break;
			default:
				break;
		}
	}
	
	if (arenaSize == kSmallArena)
	{
		switch (rightGoalLeague)
		{
			case kLittleLeague:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 512 - 208, 0, 512 - 11, 384);	/* D, 0, A, 384 */
				SectRgn(rightRgn, tempRgn, rightRgn);
				SetRectRgn(tempRgn, 512 - 140, 0, 512 - 34, 384);	/* C, 0, B, 384 */
				DiffRgn(rightRgn, tempRgn, rightRgn);
				DisposeRgn(tempRgn);
				break;
			case kJuniorVarsity:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 512 - 188, 0, 512 - 14, 384);	/* D, 0, A, 384 */
				SectRgn(rightRgn, tempRgn, rightRgn);
				SetRectRgn(tempRgn, 512 - 132, 0, 512 - 40, 384);	/* C, 0, B, 384 */
				DiffRgn(rightRgn, tempRgn, rightRgn);
				DisposeRgn(tempRgn);
				break;
			case kVarsity:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 512 - 173, 0, 512 - 19, 384);	/* D, 0, A, 384 */
				SectRgn(rightRgn, tempRgn, rightRgn);
				SetRectRgn(tempRgn, 512 - 113, 0, 512 - 50, 384);	/* C, 0, B, 384 */
				DiffRgn(rightRgn, tempRgn, rightRgn);
				DisposeRgn(tempRgn);
				break;
			case kMinorLeague:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 512 - 166, 0, 512 - 22, 384);	/* D, 0, A, 384 */
				SectRgn(rightRgn, tempRgn, rightRgn);
				SetRectRgn(tempRgn, 512 - 104, 0, 512 - 55, 384);	/* C, 0, B, 384 */
				DiffRgn(rightRgn, tempRgn, rightRgn);
				DisposeRgn(tempRgn);
				break;
			case kProfessional:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 512 - 154, 0, 512 - 27, 384);	/* D, 0, A, 384 */
				SectRgn(rightRgn, tempRgn, rightRgn);
				SetRectRgn(tempRgn, 512 - 82, 0, 512 - 69, 384);	/* C, 0, B, 384 */
				DiffRgn(rightRgn, tempRgn, rightRgn);
				DisposeRgn(tempRgn);
				break;
			default:
				break;
		}
	}
	else
	{
		switch (rightGoalLeague)
		{
			case kLittleLeague:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 640 - 246, 0, 640 - 20, 480);	/* D, 0, A, 480 */
				SectRgn(rightRgn, tempRgn, rightRgn);
				SetRectRgn(tempRgn, 640 - 174, 0, 640 - 47, 480);	/* C, 0, B, 480 */
				DiffRgn(rightRgn, tempRgn, rightRgn);
				DisposeRgn(tempRgn);
				break;
			case kJuniorVarsity:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 640 - 230, 0, 640 - 25, 480);	/* D, 0, A, 480 */
				SectRgn(rightRgn, tempRgn, rightRgn);
				SetRectRgn(tempRgn, 640 - 158, 0, 640 - 58, 480);	/* C, 0, B, 480 */
				DiffRgn(rightRgn, tempRgn, rightRgn);
				DisposeRgn(tempRgn);
				break;
			case kVarsity:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 640 - 208, 0, 640 - 32, 480);	/* D, 0, A, 480 */
				SectRgn(rightRgn, tempRgn, rightRgn);
				SetRectRgn(tempRgn, 640 - 145, 0, 640 - 67, 480);	/* C, 0, B, 480 */
				DiffRgn(rightRgn, tempRgn, rightRgn);
				DisposeRgn(tempRgn);
				break;
			case kMinorLeague:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 640 - 190, 0, 640 - 42, 480);	/* D, 0, A, 480 */
				SectRgn(rightRgn, tempRgn, rightRgn);
				SetRectRgn(tempRgn, 640 - 125, 0, 640 - 80, 480);	/* C, 0, B, 480 */
				DiffRgn(rightRgn, tempRgn, rightRgn);
				DisposeRgn(tempRgn);
				break;
			case kProfessional:
				tempRgn = NewRgn();
				SetRectRgn(tempRgn, 640 - 170, 0, 640 - 50, 480);	/* D, 0, A, 480 */
				SectRgn(rightRgn, tempRgn, rightRgn);
				SetRectRgn(tempRgn, 640 - 110, 0, 640 - 96, 480);	/* C, 0, B, 480 */
				DiffRgn(rightRgn, tempRgn, rightRgn);
				DisposeRgn(tempRgn);
				break;
			default:
				break;
		}
	}
	
	GetPort(&wasPort);
	
	if (isColor)
	{
		SetPort((GrafPtr)offCBackPtr);
		
		Index2Color(kYellowColor4Bit, &theRGBColor);
		RGBForeColor(&theRGBColor);
		OffsetRgn(leftRgn, -1, -1);
		PaintRgn(leftRgn);
		OffsetRgn(leftRgn, 1, 1);
		OffsetRgn(rightRgn, 1, -1);
		PaintRgn(rightRgn);
		OffsetRgn(rightRgn, -1, 1);
		
		Index2Color(kBlueColor4Bit, &theRGBColor);
		RGBForeColor(&theRGBColor);
		PaintRgn(leftRgn);
		
		Index2Color(kVioletColor4Bit, &theRGBColor);
		RGBForeColor(&theRGBColor);
		PaintRgn(rightRgn);
		
		RGBForeColor(&RGBBlackColor);
	}
	else
	{
		SetPort((GrafPtr)offBackPtr);
		
		OffsetRgn(leftRgn, -1, -1);
		FillRgn(leftRgn, white);
		OffsetRgn(leftRgn, 1, 1);
		OffsetRgn(rightRgn, 1, -1);
		FillRgn(rightRgn, white);
		OffsetRgn(rightRgn, -1, 1);
		
		FillRgn(leftRgn, white);
		FillRgn(rightRgn, gray);
	}
	
	if (leftRgn != kNilPointer)
		DisposeRgn(leftRgn);
	if (rightRgn != kNilPointer)
		DisposeRgn(rightRgn);
	
	if (isColor)
	{
		CopyBits(&((GrafPtr)offCBackPtr)->portBits, &((GrafPtr)offCWorkPtr)->portBits, 
				&offWorkRect, &offWorkRect, srcCopy, kNilPointer);
		if ((drawToMain) && (!splashIsUp))
		{
			CopyBits(&((GrafPtr)offCBackPtr)->portBits, &(((GrafPtr)mainWndo)->portBits), 
					&offWorkRect, &offWorkRect, srcCopy, ((GrafPtr)mainWndo)->visRgn);
		}
	}
	else
	{
		CopyBits(&offBackBits, &offWorkBits, &offWorkRect, &offWorkRect, srcCopy, 
				kNilPointer);
		if ((drawToMain) && (!splashIsUp))
		{
			CopyBits(&offBackBits, &(mainWndo->portBits), &offWorkRect, &offWorkRect, 
					srcCopy, mainWndo->visRgn);
		}
	}
	
	SetPort((GrafPtr)wasPort);
}


/*========================================================  RefreshMainWindow  */

void RefreshMainWindow (void)

{
	Rect			borderRect;
	GrafPtr			wasPort;
	Point			zeroPoint;
	short			playWide, playHigh;
	
	GetPort(&wasPort);
	SetPort((GrafPtr)mainWndo);
	
	PenNormal();
	playHigh = offWorkRect.bottom - offWorkRect.top;
	playWide = offWorkRect.right - offWorkRect.left;
	
	GetOrigin(&zeroPoint);
	SetOrigin(0, 0);
	
	borderRect = screenBits.bounds;
	if (primaryMode != kPlayMode)
		borderRect.top += GetMBarHeight();
	
	ClipRect(&borderRect);
	
	SetRect(&borderRect, screenBits.bounds.left, screenBits.bounds.top, 
			screenBits.bounds.right, -zeroPoint.v);
	FillRect(&borderRect, black);			/* top peice */
	
	SetRect(&borderRect, screenBits.bounds.left, playHigh - zeroPoint.v, 
			screenBits.bounds.right, screenBits.bounds.bottom);
	FillRect(&borderRect, black);			/* bottom peice */
	
	SetRect(&borderRect, screenBits.bounds.left, -zeroPoint.v, -zeroPoint.h, 
			playHigh - zeroPoint.v);
	FillRect(&borderRect, black);			/* left peice */
	
	SetRect(&borderRect, playWide - zeroPoint.h, -zeroPoint.v, screenBits.bounds.right, 
			playHigh - zeroPoint.v);
	FillRect(&borderRect, black);			/* right peice */
	
	SetOrigin(zeroPoint.h, zeroPoint.v);
	
	DrawAllStars();
	
	if (isColor)
		CopyBits(&((GrafPtr)offCWorkPtr)->portBits, &(((GrafPtr)mainWndo)->portBits), 
				&offWorkRect, &offWorkRect, srcCopy, ((GrafPtr)mainWndo)->visRgn);
	else
		CopyBits(&offWorkBits, &(mainWndo->portBits), &offWorkRect, &offWorkRect, 
				srcCopy, mainWndo->visRgn);
	
	DisplayPlayerFouls(0);
	DisplayOpponentFouls(0);
	
	SetPort((GrafPtr)wasPort);
}


/*========================================================  OpenMainWindow  */

void OpenMainWindow (void)

{
	if (isColor)
	{
		mainWndo = GetNewCWindow(rMainWndoID, kNilPointer, kPutInFront );
	}
	else
	{
		mainWndo = GetNewWindow(rMainWndoID, kNilPointer, kPutInFront );
	}
	
	horizontal = screenBits.bounds.right - screenBits.bounds.left;
	vertical = screenBits.bounds.bottom - screenBits.bounds.top;
	SizeWindow((GrafPtr)mainWndo, horizontal, vertical, kNormalUpdates);
	ShowWindow((GrafPtr)mainWndo);
	SetPort((GrafPtr)mainWndo);
	ClipRect(&screenBits.bounds);
	
	if (!isColor)
		FillRect(&screenBits.bounds, black);
	
	horizontal = (screenWide - (screenBits.bounds.right - screenBits.bounds.left)) / 2;
	vertical = (screenHigh - (screenBits.bounds.bottom - screenBits.bounds.top)) / 2;
	SetOrigin(horizontal, vertical);
	
	if (isColor)	/* If in color, we need to dick with palettes */
	{
		Index2Color(kBlackColor4Bit, &RGBBlackColor);
		Index2Color(kWhiteColor4Bit, &RGBWhiteColor);
		RGBForeColor(&RGBBlackColor);
		RGBBackColor(&RGBWhiteColor);
	}
	
					/* Define dragRect for limiting dragging of a window */
	dragRect = screenBits.bounds;
	dragRect.top += 30;		/* menu bar height + title bar height */
	InsetRect(&dragRect, 4, 4);
}


/*========================================================  DoSplashScreen  */

void DoSplashScreen (void)

{
	Rect			frame;
	GrafPtr			wasPort;
	PicHandle		thePict;
	Point			origin;
	
	GetPort((GrafPtr *)&wasPort);
	SetPort((GrafPtr)mainWndo);
	splashIsUp = TRUE;
	
	GetOrigin(&origin);
	SetOrigin(0, 0);
	
	if (isColor)
		thePict = GetPicture(rSplashPICT4);
	else
		thePict = GetPicture(rSplashPICT1);
	
	if (thePict != kNilPointer)
	{
		HLock((Handle)thePict);
		frame = (**thePict).picFrame;
		HUnlock((Handle)thePict);
		OffsetRect(&frame, -frame.left, -frame.top);
		
		OffsetRect(&frame, 0, ((screenBits.bounds.bottom - screenBits.bounds.top - 
				frame.bottom - 20) / 2) + 10);
		
		if ((screenBits.bounds.right - screenBits.bounds.left) < frame.right)
		{
			OffsetRect(&frame, screenBits.bounds.right - screenBits.bounds.left - 
					frame.right, 0);
		}
		else if ((screenBits.bounds.right - screenBits.bounds.left) > frame.right)
		{
			OffsetRect(&frame, (screenBits.bounds.right - screenBits.bounds.left - 
					frame.right) / 2, 0);
		}
		
		DrawPicture(thePict, &frame);
		
		ReleaseResource((Handle)thePict);
	}
	
	SetOrigin(origin.h, origin.v);
	SetPort((GrafPtr)wasPort);
}


/*========================================================  CloseMainWindow  */

void CloseMainWindow (void)

{
	if (mainWndo != kNilPointer)
		DisposeWindow((GrafPtr)mainWndo);
}


