class LuaWidget(theCObj)
{
	def mCObj = theCObj;
	def mUpdateCnt = 0;
	def mChildren = {};
	setprot(mChildren, "l");
	
	DProps.WidgetCreated(self);
	
	:SetLinkedObject(theCObj, self);
	theCObj:RegisterObject();
}

function LuaWidget:Create(theParent)
{
	local aWidget = gApp:CreateLuaWidget(self);
	theParent:AddWidget(aWidget);
	return aWidget;
}

function LuaWidget:CObjDeleted()
{
	DProps.WidgetDeleted(self);
}

//////////////////////////////////////////////////////////////////////////

function LuaWidget:Update()
{
	mUpdateCnt++;
	mCObj:Update();
}

function LuaWidget:Draw(g)
{
	mCObj:Draw();
}

function LuaWidget:DrawOverlay(g)
{
	mCObj:DrawOverlay();
}

function LuaWidget:IsPointVisible(theX, theY)
{
	return true;
}

function LuaWidget:MouseEnter()
{
	mCObj:MouseEnter();
}

function LuaWidget:MouseLeave()
{
	mCObj:MouseLeave();
}

function LuaWidget:MouseMove(theX, theY)
{
	mCObj:MouseMove(theX, theY);
}

function LuaWidget:MouseDrag(theX, theY)
{
	mCObj:MouseDrag(theX, theY);
}

function LuaWidget:MouseDown(theX, theY, theBtnNum, theClickCount)	
{
	mCObj:MouseDown(theX, theY, theBtnNum, theClickCount);
}

function LuaWidget:MouseUp(theX, theY, theBtnNum, theClickCount)
{
	mCObj:MouseUp(theX, theY, theBtnNum, theClickCount);
}

function LuaWidget:MouseWheel(theDelta)
{
	mCObj:MouseWheel(theDelta);
}

function LuaWidget:KeyChar(theChar)
{
	mCObj:KeyChar(theChar);
}

function LuaWidget:KeyDown(theKey)
{
	mCObj:KeyDown(theKey);
}

function LuaWidget:KeyUp(theKey)
{
	mCObj:KeyUp(theKey);
}

function LuaWidget:GotFocus()
{
	mCObj:GotFocus();
}

function LuaWidget:LostFocus()
{
	mCObj:LostFocus();
}

function LuaWidget:WantsFocus()
{
	return 	mCObj:WantsFocus();
}

///
function LuaWidget:CheckboxChecked(theId, checked)
{
	mCObj:CheckboxChecked(theId, checked);
}

function LuaWidget:ButtonPress(theBtnId, theClickCount)
{
	mCObj:ButtonPress(theBtnId, theClickCount);
}

function LuaWidget:ButtonDepress(theBtnId)
{
	mCObj:ButtonDepress(theBtnId);
}

function LuaWidget:ButtonMouseEnter(theId)
{
	mCObj:ButtonMouseEnter(theId);
}

function LuaWidget:ButtonMouseLeave(theId)
{
	mCObj:ButtonMouseLeave(theId);
}

function LuaWidget:ButtonMouseMove(theId, theX, theY)
{
	mCObj:ButtonMouseMove(theId, theX, theY);
}

function LuaWidget:ButtonDownTick(theId, theClickCount)
{
	mCObj:ButtonDownTick(theId, theClickCount);
}

function LuaWidget:ScrollPosition(theId, thePosition)
{
	mCObj:ScrollPosition(theId, thePosition);
}

function LuaWidget:EditWidgetText(theId, theString)
{
	mCObj:EditWidgetText(theId, theString);
}

function LuaWidget:AllowKey(theId, theKey)
{
	return mCObj:AllowKey(theId, theKey);
}

function LuaWidget:AllowChar(theId, theChar)
{
	return mCObj:AllowChar(theId, theChar);
}

function LuaWidget:AllowText(theId, theText)
{
	return mCObj:AllowText(theId, theText);
}

function LuaWidget:ListClicked(theId, theIdx, theClickCount)
{
	mCObj:ListClicked(theId, theIdx, theClickCount);
}

function LuaWidget:ListClosed(theId)
{
	mCObj:ListClosed(theId);
}

function LuaWidget:ListHiliteChanged(theId, theOldIdx, theNewIdx)
{
	mCObj:ListHiliteChanged(theId, theOldIdx, theNewIdx);
}

//////////////////////////////////////////////////////////////////////////

function LuaWidget:Resize(theX, theY, theWidth, theHeight)
{
	mCObj:Resize(theX, theY, theWidth, theHeight);
}

function LuaWidget:Resize_DYN(thePos, theX, theY, theWidth, theHeight)
{
	Resize(theX, theY, theWidth, theHeight);
	dptrack(thePos, {self, LuaWidget.Resize, 0, {"X", "Y", "Width", "Height"}, {theX, theY, theWidth, theHeight}});
}

function LuaWidget:Move(theX, theY)
{
	mCObj:Resize(theX, theY, mCObj:GetWidth(), mCObj:GetHeight());
}

function LuaWidget:SetColors(theColors)
{
	mCObj:SetColors(theColors);
}

function LuaWidget:SetColors_DYN(thePos, theColors)
{
	mCObj:SetColors(theColors);
	dptrack(thePos, {self, LuaWidget.SetColors, 0, {"Colors"}, {theColors}});
}

function LuaWidget:AddWidget(theWidget)
{
	if (table.contains(theWidget.mCObj, "GetID"))
		mChildren[theWidget.mCObj:GetID()] = theWidget;
	mCObj:AddWidget(theWidget.mCObj);
}

function LuaWidget:RemoveWidget(theWidget)
{
	if (table.contains(theWidget.mCObj, "GetID"))
		mChildren[theWidget.mCObj:GetID()] = nil;
	mCObj:RemoveWidget(theWidget.mCObj);
}


//////////////////////////////////////////////////////////////////////////

RegisterLinkedClass("LuaWidget", LuaWidget);
