#include "tk_dpoption.h"
#include "../tk_base.h"
#include "../../../exceptions/exceptions.h"

const char* TkDestroyProtocolOption::type="TkDestroyProtocolOption";

const char* TkDestroyProtocolOption::getType() const
{
	return type;
}

void TkDestroyProtocolOption::doSerialize(TiXmlElement& element) const
{
	element.SetAttribute("customProtocol",customProtocol?1:0);
}

void TkDestroyProtocolOption::doDeserialize(const TiXmlElement& element)
{
	int intCustomProtocol;
	element.Attribute("customProtocol",&intCustomProtocol);
	customProtocol=(intCustomProtocol!=0);
}

TkDestroyProtocolOption::TkDestroyProtocolOption()
{
	this->customProtocol=false;
}

TkDestroyProtocolOption::TkDestroyProtocolOption(bool customProtocol)
{
	this->customProtocol=customProtocol;
}

const string& TkDestroyProtocolOption::toString() const
{
	string cmd="WM_DELETE_WINDOW";
	if (customProtocol)
	{
		if (widget->getUid()==0) throw new ExceptionNullPtr(type);
		cmd=cmd+" {ondeletewindow "+widget->getGeneratedId()+"}";
	}
	return *(new string(cmd));
}

void TkDestroyProtocolOption::fromObject(Tcl_Obj* object)
{
	throw ExceptionNoImplementation(type,"fromString");
}
