#include "AllTools.h"

Rect GetDRect( DialogPtr dialog, short itemNo )
{
short			iType;
Handle			iHandle;
Rect			iRect;

GetDItem( dialog, itemNo, &iType, &iHandle, &iRect);

return iRect;
}

void SetDRect(DialogPtr dialog, short	itemNo, Rect rect)
{
short			iType;
Handle			iHandle;
Rect			iRect;

GetDItem( dialog, itemNo, &iType, &iHandle, &iRect);
SetDItem( dialog, itemNo, iType, iHandle, &rect);
}

void SetTheInfoStr(DialogPtr theDialog, short	itemNo, Str255 aValue)
{
short			iType;
Handle			iHandle;
Rect			iRect;

GetDItem( theDialog, itemNo, &iType, &iHandle, &iRect);
SetIText(iHandle, aValue);
}

void SetTheInfo(DialogPtr theDialog, short	itemNo, long aValue)
{
short			iType;
Handle			iHandle;
Rect			iRect;
Str255			Strng;

GetDItem( theDialog, itemNo, &iType, &iHandle, &iRect);
NumToString(aValue, Strng);
SetIText(iHandle, Strng);
}

void GetTheInfoStr(DialogPtr theDialog, short itemNo, StringHandle string)
{
short			iType;
Handle			iHandle;
Rect			iRect;

GetDItem( theDialog, itemNo, &iType, &iHandle, &iRect);
GetIText(iHandle, *string);
}

short GetTheInfo(DialogPtr theDialog, short itemNo)
{
short			iType;
Handle			iHandle;
Rect			iRect;
long			num;
Str255			string;

GetDItem( theDialog, itemNo, &iType, &iHandle, &iRect);
GetIText(iHandle, string);
StringToNum(string, &num);

return (short)num;
}

void CenterDialog(DialogPtr dialog, videoInfo theScreen)
{
Rect	dialogRect;
short	dialogWidth, dialogDepth;

dialogRect = ((DialogPeek)dialog)->window.port.portRect;
dialogWidth = dialogRect.left - dialogRect.right;
dialogDepth = dialogRect.top - dialogRect.bottom;

	MoveWindow(dialog, ((theScreen.resolutionX + dialogWidth) >> 1), 
								((theScreen.resolutionY + dialogDepth) >> 1), FALSE);
}

void ToggleCheckBox(DialogPtr dialog, short item)
{
	short type;
	Handle itemHdl;
	Rect box;

	GetDItem(dialog, item, &type, &itemHdl, &box);
	SetCtlValue((ControlHandle)itemHdl, (GetCtlValue((ControlHandle)itemHdl) == 0) ? 1 : 0);
}

void SetCheck(DialogPtr dPtr, short ChkItem, short value)
{
	short theType;
	Handle theItem;
	Rect theBox;

	GetDItem(dPtr, ChkItem, &theType, &theItem, &theBox);
	SetCtlValue((ControlHandle)theItem, value);
}