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

class LuaDialog : LuaWidget(theCObj)
{
	super:Init(theCObj);
}

function LuaDialog:Create(theComponentImage, theButtonComponentImage,
	theId, isModal, theDialogHeader, theDialogLines, theDialogFooter, theButtonMode)
{
	local aWidget = gApp:CreateDialog(theComponentImage, theButtonComponentImage,
		theId, isModal, theDialogHeader, theDialogLines, theDialogFooter, theButtonMode, self);
	gCApp:GetWidgetManager():AddWidget(aWidget.mCObj);
	return aWidget;
}

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

class LuaButtonWidget : LuaWidget(theCObj)
{
	super:Init(theCObj);
}

function LuaButtonWidget:Create(theId, theParent)
{
	local aWidget = gApp:CreateButtonWidget(theId, theParent, self);
	theParent:AddWidget(aWidget);
	return aWidget;
}

function LuaButtonWidget:SetLabel(theStr)
{
	mCObj:SetLabel(theStr);
}

function LuaButtonWidget:SetLabel_DYN(thePos, theStr)
{
	SetLabel(theStr);
	dptrack(thePos, {self, SetLabel, 0, {"Label"}, {theStr}});
}

function LuaButtonWidget.DPGetDefaultSize()
{
	return 80, 24;
}

function LuaButtonWidget.DPGetCreateDefault(thePos, theParent, theX, theY, theWidth, theHeight)
{
	local aWidget = LuaButtonWidget:Create(-1, theParent);
	thePos[1]++; 
	aWidget:SetLabel_DYN(thePos, "Button");
	thePos[1]++;
	aWidget:Resize_DYN(thePos, theX, theY, theWidth, theHeight);
	
	return aWidget, {"local aButton = LuaButtonWidget:Create(-1, self);",
		"aButton:SetLabel_DYN(__POS, \"Button\");",
		"aButton:Resize_DYN(__POS, " .. theX .. ", " .. theY .. ", " .. theWidth .. ", " .. theHeight .. ");"};
}

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

class LuaCheckboxWidget : LuaWidget(theCObj)
{
	super:Init(theCObj);
}

function LuaCheckboxWidget:Create(theId, theParent)
{
	local aWidget = gApp:CreateCheckboxWidget(nil, nil, theId, theParent, self);
	theParent:AddWidget(aWidget);
	return aWidget;
}

function LuaCheckboxWidget.DPGetDefaultSize()
{
	return 16, 16;
}

function LuaCheckboxWidget:SetChecked(checked)
{
	mCObj:SetChecked(checked);
}

function LuaCheckboxWidget:SetChecked_DYN(thePos, checked)
{
	SetChecked(checked);
	dptrack(thePos, {self, SetChecked, 0, {"Checked"}, {checked}});
}

function LuaCheckboxWidget.DPGetCreateDefault(thePos, theParent, theX, theY, theWidth, theHeight)
{
	local aWidget = LuaCheckboxWidget:Create(-1, theParent);
	thePos[1]++; 
	aWidget:Resize_DYN(thePos, theX, theY, theWidth, theHeight);
	thePos[1]++; 
	aWidget:SetChecked_DYN(thePos, false);
	
	return aWidget, {"local aCheckbox = LuaCheckboxWidget:Create(-1, self);",
		"aCheckbox:SetChecked_DYN(__POS, false);",
		"aCheckbox:Resize_DYN(__POS, " .. theX .. ", " .. theY .. ", " .. theWidth .. ", " .. theHeight .. ");"};
}

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

class LuaEditWidget : LuaWidget(theCObj)
{
	super:Init(theCObj);
}

function LuaEditWidget:Create(theId, theParent)
{
	local aWidget = gApp:CreateEditWidget(theId, theParent, self);
	theParent:AddWidget(aWidget);
	return aWidget;
}

function LuaEditWidget.DPGetDefaultSize()
{
	return 80, 24;
}

function LuaEditWidget.DPGetCreateDefault(thePos, theParent, theX, theY, theWidth, theHeight)
{
	local aWidget = LuaEditWidget:Create(-1, theParent);
	thePos[1]++; 
	aWidget:Resize_DYN(thePos, theX, theY, theWidth, theHeight);
	
	return aWidget, {"local aEdit = LuaEditWidget:Create(-1, self);",
		"aEdit:Resize_DYN(__POS, " .. theX .. ", " .. theY .. ", " .. theWidth .. ", " .. theHeight .. ");"};
}

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

class LuaListWidget : LuaWidget(theCObj)
{
	super:Init(theCObj);
}

function LuaListWidget:Create(theId, theParent)
{
	local aWidget = gApp:CreateListWidget(theId, nil, theParent, self);
	theParent:AddWidget(aWidget);
	return aWidget;
}

function LuaListWidget.DPGetDefaultSize()
{
	return 80, 64;
}

function LuaListWidget.DPGetCreateDefault(thePos, theParent, theX, theY, theWidth, theHeight)
{
	local aWidget = LuaListWidget:Create(-1, theParent);
	thePos[1]++; 
	aWidget:Resize_DYN(thePos, theX, theY, theWidth, theHeight);
	
	return aWidget, {"local aList = LuaListWidget:Create(-1, self);",
		"aList:Resize_DYN(__POS, " .. theX .. ", " .. theY .. ", " .. theWidth .. ", " .. theHeight .. ");"};
}

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

class LuaTextWidget : LuaWidget(theCObj)
{
	super:Init(theCObj);
}

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

function LuaTextWidget:IsPointVisible(theX, theY)
{
	// Allow us to select it if we're editing
	return DProps.mEditing;
}

function LuaTextWidget:SetLabel(theStr)
{
	mCObj:SetLabel(theStr);
}

function LuaTextWidget:SetLabel_DYN(thePos, theStr)
{
	SetLabel(theStr);
	dptrack(thePos, {self, SetLabel, 0, {"Label"}, {theStr}});
}

function LuaTextWidget:SetLineSpacing(theLineSpacing)
{
	mCObj:SetLineSpacing(theLineSpacing);
}

function LuaTextWidget:SetLineSpacing_DYN(thePos, theLineSpacing)
{
	SetLineSpacing(theLineSpacing);
	dptrack(thePos, {self, SetLineSpacing, 0, {"Line Spacing"}, {theLineSpacing}});
}

function LuaTextWidget:SetJustification(theJustification)
{
	mCObj:SetJustification(theJustification);
}

function LuaTextWidget:SetJustification_DYN(thePos, theJustification)
{
	SetJustification(theJustification);
	dptrack(thePos, {self, SetJustification, 0, {"Justification"}, {theJustification}});
}

function LuaTextWidget.DPGetDefaultSize()
{
	return 128, 16;
}

function LuaTextWidget.DPGetCreateDefault(thePos, theParent, theX, theY, theWidth, theHeight)
{
	local aWidget = LuaTextWidget:Create(theParent);
	thePos[1]++; 
	aWidget:SetLabel_DYN(thePos, "Text");
	thePos[1]++;
	aWidget:SetLineSpacing_DYN(thePos, -1);
	thePos[1]++;
	aWidget:SetJustification_DYN(thePos, -1);
	thePos[1]++;
	aWidget:Resize_DYN(thePos, theX, theY, theWidth, theHeight);
	thePos[1]++;
	aWidget:SetColors_DYN(thePos, {0xFFFFFFFF});
	
	return aWidget, {"local aText = LuaTextWidget:Create(self);",
		"aText:SetLabel_DYN(__POS, \"Text\");",
		"aText:SetLineSpacing_DYN(__POS, -1);",
		"aText:SetJustification_DYN(__POS, -1);",
		"aText:Resize_DYN(__POS, " .. theX .. ", " .. theY .. ", " .. theWidth .. ", " .. theHeight .. ");",
		"aText:SetColors_DYN(__POS, {0xFFFFFFFF});"};
}

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

class LuaScrollbarWidget : LuaWidget(theCObj)
{
	super:Init(theCObj);
}

function LuaScrollbarWidget:Create(theId, theParent)
{
	local aWidget = gApp:CreateScrollbarWidget(theId, theParent, self);
	theParent:AddWidget(aWidget);
	return aWidget;
}

function LuaScrollbarWidget:ResizeScrollbar(theX, theY, theWidth, theHeight)
{
	mCObj:ResizeScrollbar(theX, theY, theWidth, theHeight);
}

function LuaScrollbarWidget:ResizeScrollbar_DYN(thePos, theX, theY, theWidth, theHeight)
{
	ResizeScrollbar(theX, theY, theWidth, theHeight);
	dptrack(thePos, {self, LuaScrollbarWidget.ResizeScrollbar, 0, {"X", "Y", "Width", "Height"}, {theX, theY, theWidth, theHeight}});
}

function LuaScrollbarWidget.DPGetDefaultSize()
{
	return 16, 64;
}

function LuaScrollbarWidget.DPGetCreateDefault(thePos, theParent, theX, theY, theWidth, theHeight)
{
	local aWidget = LuaScrollbarWidget:Create(-1, theParent);
	thePos[1]++; 
	aWidget:ResizeScrollbar_DYN(thePos, theX, theY, theWidth, theHeight);
	
	return aWidget, {"local aScrollbar = LuaScrollbarWidget:Create(-1, self);",
		"aScrollbar:ResizeScrollbar_DYN(__POS, " .. theX .. ", " .. theY .. ", " .. theWidth .. ", " .. theHeight .. ");"};
}

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

class LuaHorzScrollbarWidget : LuaScrollbarWidget(theCObj)
{
	super:Init(theCObj);
}

function LuaHorzScrollbarWidget:Create(theId, theParent)
{
	local aWidget = gApp:CreateScrollbarWidget(theId, theParent, self);
	theParent:AddWidget(aWidget);
	aWidget.mCObj:SetHorizontal(true);
	return aWidget;
}

function LuaHorzScrollbarWidget.DPGetDefaultSize()
{
	return 64, 16;
}

function LuaHorzScrollbarWidget.DPGetCreateDefault(thePos, theParent, theX, theY, theWidth, theHeight)
{
	local aWidget = LuaHorzScrollbarWidget:Create(-1, theParent);
	thePos[1]++; 
	aWidget:ResizeScrollbar_DYN(thePos, theX, theY, theWidth, theHeight);
	
	return aWidget, {"local aScrollbar = LuaHorzScrollbarWidget:Create(-1, self);",
		"aScrollbar:ResizeScrollbar_DYN(__POS, " .. theX .. ", " .. theY .. ", " .. theWidth .. ", " .. theHeight .. ");"};
}

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

class LuaHyperlinkWidget : LuaWidget(theCObj)
{
	super:Init(theCObj);
}

function LuaHyperlinkWidget:Create(theId, theParent)
{
	local aWidget = gApp:CreateHyperlinkWidget(theId, theParent, self);
	theParent:AddWidget(aWidget);
	return aWidget;
}

function LuaHyperlinkWidget:SetLabel(theStr)
{
	mCObj:SetLabel(theStr);
}

function LuaHyperlinkWidget:SetLabel_DYN(thePos, theStr)
{
	SetLabel(theStr);
	dptrack(thePos, {self, SetLabel, 0, {"Label"}, {theStr}});
}

function LuaHyperlinkWidget.DPGetDefaultSize()
{
	return 128, 20;
}

function LuaHyperlinkWidget.DPGetCreateDefault(thePos, theParent, theX, theY, theWidth, theHeight)
{
	local aWidget = LuaHyperlinkWidget:Create(-1, theParent);
	thePos[1]++; 
	aWidget:SetLabel_DYN(thePos, "Hyperlink");
	thePos[1]++;
	aWidget:Resize_DYN(thePos, theX, theY, theWidth, theHeight);
	thePos[1]++;
	aWidget:SetColors_DYN(thePos, {0xFFFFFF00, 0xFFFFFFFF});
	
	return aWidget, {"local aHyperlink = LuaHyperlinkWidget:Create(-1, self);",
		"aHyperlink:SetLabel_DYN(__POS, \"Hyperlink\");",
		"aHyperlink:Resize_DYN(__POS, " .. theX .. ", " .. theY .. ", " .. theWidth .. ", " .. theHeight .. ");",
		"aHyperlink:SetColors_DYN(__POS, {0xFFFFFF00, 0xFFFFFFFF});"};
}

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

DProps.AddWidgetType("Button", LuaButtonWidget, nil, 0);
DProps.AddWidgetType("Checkbox", LuaCheckboxWidget, nil, 1);
DProps.AddWidgetType("Edit", LuaEditWidget, nil, 2);
DProps.AddWidgetType("List", LuaListWidget, nil, 3);
DProps.AddWidgetType("Text", LuaTextWidget, nil, 4);
DProps.AddWidgetType("Horz Scrollbar", LuaHorzScrollbarWidget, nil, 5);
DProps.AddWidgetType("Vert Scrollbar", LuaScrollbarWidget, nil, 6);
DProps.AddWidgetType("Hyperlink", LuaHyperlinkWidget, nil, 7);

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

RegisterLinkedClass("LuaButtonWidget", LuaButtonWidget);
